While 1x zelfde resultaat

Gestart doorBartv5 reacties43 weergaven

6 berichten · pagina 1 van 1

Bartv

Lid · Topicstarter

Berichten
4.451
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Hallo,

Als ik een while doe, dan krijg ik alle resultaten en die laat ik echoen, nu wil ik als er 2x hetzelfde resultaat komt, hij hem maar 1x laat zien. Ik heb nu dit:

[COLOR= #0000BB]<?php
$chq[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM devices"[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]());[/COLOR]
?>
<select name="ch">
                        [COLOR= #0000BB]<?php[/COLOR]
                        [URL="http://www.php.net/while"]while[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$chf[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$chq[/COLOR][COLOR= #007700]))
                        {[/COLOR]
                            [URL="http://www.php.net/echo"]echo[/URL][COLOR= #DD0000]<option value=[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$chf[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]channel[/COLOR][COLOR= #007700]] .[/COLOR] [COLOR= #DD0000]>[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$chf[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]channel[/COLOR][COLOR= #007700]] .[/COLOR] [COLOR= #DD0000]</option>[/COLOR][COLOR= #007700];
                        }[/COLOR]
                        ?>
                        <option value="all">Iedereen</option>
                    </select>


In de database hebben 2 devices dezelfde channel, maar bij option (das ook wel duidelijk met deze code) laat hij 2x hetzelfde channel zien. Ik wil als er meerdere devices hetzelfde channel hebben, dat hij hem maar 1x laat zien bij het option menu, hoe doe ik dat?

Gr Bart
0
Berichten
3.788
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Voeg in de while $chf[channel] toe aan een array en controleer steeds voor het weergeven of de huidige channel al in die array staat
0
Bartv

Lid · Topicstarter

Berichten
4.451
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Eleky schreef:
Voeg in de while $chf[channel] toe aan een array en controleer steeds voor het weergeven of de huidige channel al in die array staat
Kan je een voorbeeld geven? ik snap het een beetje, maar niet helemaal zoals het moet gebeuren zegmaar
0
Berichten
2.692
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
of in de Query:
SELECT * FROM devices GROUP BY channel
0
Berichten
3.788
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
[COLOR= #0000BB]<?php
$chq[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM devices"[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]());[/COLOR]
?>
<select name="ch">
                        [COLOR= #0000BB]<?php
                        $arry[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/array"]array[/URL][COLOR= #007700]();[/COLOR]
                        [URL="http://www.php.net/while"]while[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$chf[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$chq[/COLOR][COLOR= #007700]))
                        {[/COLOR]
                            [URL="http://www.php.net/if"]if[/URL][COLOR= #007700](![/COLOR][URL="http://www.php.net/in_array"]in_array[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$chf[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]channel[/COLOR][COLOR= #007700]],[/COLOR] [COLOR= #0000BB]$arr[/COLOR][COLOR= #007700])){[/COLOR]
                                [URL="http://www.php.net/echo"]echo[/URL][COLOR= #DD0000]<option value=[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$chf[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]channel[/COLOR][COLOR= #007700]] .[/COLOR] [COLOR= #DD0000]>[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$chf[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]channel[/COLOR][COLOR= #007700]] .[/COLOR] [COLOR= #DD0000]</option>[/COLOR][COLOR= #007700];
                            }
                        }[/COLOR]
                        ?>
                        <option value="all">Iedereen</option>
                    </select>


toevoeging op 18 november 2012, 11:26:38:
Superb schreef:
of in de Query:
SELECT * FROM devices GROUP BY channel
Mss nog wel handiger jabiggrin
0
Bartv

Lid · Topicstarter

Berichten
4.451
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Heb die van superb geprobeerd en die werkt biggrin, bedankt ervoor! Jij ook bedankt Eleky! Misschien ga ik er wat mee doen later, maar nu is die van superb een snellere oplossing wink
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren