Query in select?

Gestart doorMarv16 reacties18 weergaven

17 berichten · pagina 1 van 2

Marv

Lid · Topicstarter

Berichten
3.092
Reputatie
1
Punten
0,21
Lid sinds
Laatst gezien
Hallo,
Ik ben bezig met een formuliertje.

Nu wil ik graag alle Usernames uit de tabel users in een select lijst hebben.

Zou dat kunnen? ik weet niet of dat mogelijk is.

Mvg
0
Berichten
20.364
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
[COLOR= #0000BB]<?php
$ledenQuery[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT
                                naam
                            FROM
                                tabel"[/COLOR][COLOR= #007700]);[/COLOR]
                                
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_num_rows"]mysql_num_rows[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$ledenQuery[/COLOR][COLOR= #007700]) >=[/COLOR] [COLOR= #0000BB]1[/COLOR][COLOR= #007700])
{[/COLOR]        
            
    ?>
    <select>
        [COLOR= #0000BB]<?php[/COLOR]
        [URL="http://www.php.net/while"]while[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$ledenFetch[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$ledenQuery[/COLOR][COLOR= #007700]))
        {[/COLOR]
        
            ?>
            <option value="">[COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$ledenFetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]naam[/COLOR][COLOR= #007700]];[/COLOR] ?></option>
            [COLOR= #0000BB]<?php[/COLOR]
            
        [COLOR= #007700]}[/COLOR]
        
        ?>
    </select>
    [COLOR= #0000BB]<?php[/COLOR]
    
[COLOR= #007700]}[/COLOR]

?>
0
Marv

Lid · Topicstarter

Berichten
3.092
Reputatie
1
Punten
0,21
Lid sinds
Laatst gezien
danku u smile
0
Berichten
435
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Dit is makkenlijker:

[COLOR= #0000BB]<?php
$query[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM klantjes ORDER BY gebruikersnaam"[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/while"]while[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$obj2[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_object"]mysql_fetch_object[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$query[/COLOR][COLOR= #007700])) {[/COLOR]
[COLOR= #0000BB]$persoon[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$obj2[/COLOR][COLOR= #007700]->[/COLOR]gebruiker[COLOR= #007700];[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL][COLOR= #DD0000]"<option value="$persoon">$persoon</option>"[/COLOR][COLOR= #007700];
}[/COLOR]
?>
0
Berichten
6.144
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
mysql_fetch_assoc is sneller als object.
0
Berichten
9.953
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Ik zal voor die van Shahiem gaan.
0
Berichten
20.364
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Efferinie schreef:
danku u smile
Geen probleem. wink
0
Berichten
435
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Zo:

[COLOR= #0000BB]<?php
$query[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM klantjes ORDER BY gebruikersnaam"[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/while"]while[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$obj2[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$query[/COLOR][COLOR= #007700])) {[/COLOR]
[COLOR= #0000BB]$persoon[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$obj2[/COLOR][COLOR= #007700]->[/COLOR]gebruiker[COLOR= #007700];[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL][COLOR= #DD0000]"<option value="$persoon">$persoon</option>"[/COLOR][COLOR= #007700];
}[/COLOR]
?>

wink
0
Berichten
6.722
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Stanieboy schreef:
Zo:

[COLOR= #0000BB]<?php
$query[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM klantjes ORDER BY gebruikersnaam"[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/while"]while[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$obj2[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$query[/COLOR][COLOR= #007700])) {[/COLOR]
[COLOR= #0000BB]$persoon[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$obj2[/COLOR][COLOR= #007700]->[/COLOR]gebruiker[COLOR= #007700];[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL][COLOR= #DD0000]"<option value="$persoon">$persoon</option>"[/COLOR][COLOR= #007700];
}[/COLOR]
?>
wink
Ooit gehoord van netjes en werkend scripten? Ik zal jouw script even transformeren naar een normaal script:

<select>
[COLOR= #0000BB]<?php
$query[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM `klantjes` ORDER BY `gebruikersnaam`"[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/while"]while[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$fetch[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$query[/COLOR][COLOR= #007700])) {[/COLOR]
      [COLOR= #0000BB]$persoon[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$fetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]gebruiker[/COLOR][COLOR= #007700]];[/COLOR]
      [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<option value="[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$persoon[/COLOR][COLOR= #007700].[/COLOR][COLOR= #DD0000]">[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$persoon[/COLOR][COLOR= #007700].[/COLOR][COLOR= #DD0000]</option>[/COLOR][COLOR= #007700];
}[/COLOR]
?>
</select>


Maar de manier van Shahiem is gewoon beter.
0
Berichten
7.681
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Stanieboy makkelijk is niet altijd beter hewink
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Ook misschien htmlentities() vergeten?
0
Berichten
6.722
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Die is niet nodig hoor...
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Wiitse schreef:
Die is niet nodig hoor...
Jawel, want die persoon zijn naam kan ook een XSSje zijn
0
Berichten
20.364
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Of html gebruiken emo
0
Berichten
994
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Lol, @Wiitse leer zelf gewoon eens netter scripten ipv andere mensen erop te wijzen.

<select name="persoon">
[COLOR= #0000BB]<?php
$query[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM klantjes ORDER BY gebruikersnaam ASC"[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/while"]while[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$get[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_object"]mysql_fetch_object[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$query[/COLOR][COLOR= #007700])) {[/COLOR]
      [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<option value="[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$get[/COLOR][COLOR= #007700]->[/COLOR]persoon[COLOR= #007700].[/COLOR][COLOR= #DD0000]">[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$get[/COLOR][COLOR= #007700]->[/COLOR]persoon[COLOR= #007700].[/COLOR][COLOR= #DD0000]</option>[/COLOR][COLOR= #007700];
}[/COLOR]
?>
</select>


Beveiliging heb niks met netheid te maken dat kun je zelf wel 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