Page 1 of 1

display in drop down menu

Posted: Thu May 27, 2004 6:43 am
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

Posted: Thu May 27, 2004 7:37 am
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

Posted: Thu May 27, 2004 9:47 am
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...~!

Posted: Thu May 27, 2004 9:51 am
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"; 
?>