display in drop down menu

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
merican
Forum Newbie
Posts: 22
Joined: Tue May 18, 2004 8:56 pm

display in drop down menu

Post by merican »

hi ,
let say i want to display username drop down menu from ffdb_user SQL table. can someone teach me the code for that.

thank you inadvance,
regards,
alfy
dave420
Forum Contributor
Posts: 106
Joined: Tue Feb 17, 2004 8:03 am

Post by dave420 »

If I understand you correctly, you want to display a list of usernames in a drop-down (select) box? If so, the basic logic goes as this:

Output the start of a select tag ("<select name='user'>")
Get a list of users from the database ("select * from user", for example).
Iterate through the users and output a row of HTML for an option element: "<option value='".$row["userID"]."'>".$row["username"]."</option>"
Output an end tag ("</select>")

If you're using templates, there are more tidy ways to do it, but the logic is still the same.

dave
kevin7
Forum Commoner
Posts: 96
Joined: Fri May 21, 2004 6:54 am

Post by kevin7 »

hmm....

i will skip for the database connection...

Code: Select all

$result = mysql_query("SELECT id, username FROM ffdb_user");

echo "<SELECT>";

while ($myrow = mysql_fetch_row($result)) &#123;

     echo "<OPTION value=$myrow&#1111;0]>$myrow&#1111;1]>";

&#125;

echo "</SELECT>";


editted: ooo... forgot... no need that </OPTION> can work also...~!
Last edited by kevin7 on Thu May 27, 2004 10:24 am, edited 1 time in total.
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

got to close that option tag!

Code: Select all

<?php
//from 
echo "<OPTION value=$myrow[0]>$myrow[1]"; 

//to
echo "<OPTION value=$myrow[0]>$myrow[1]</OPTION>\n"; 
?>
Post Reply