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
display in drop down menu
Moderator: General Moderators
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
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
hmm....
i will skip for the database connection...
editted: ooo... forgot... no need that </OPTION> can work also...~!
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)) {
echo "<OPTION value=$myrowї0]>$myrowї1]>";
}
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
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";
?>