how can i make a mysql loop and then echo it in a drop down menu? You know what I mean? like the drop down menu in the top left of P2L header, how can I do that, but with usernames, and now have to insert all them individually?
drop down menu/loop
Started by Chris., Sep 24 2006 06:45 PM
6 replies to this topic
#1
Posted 24 September 2006 - 06:45 PM
#2
Posted 24 September 2006 - 07:07 PM
I'm not entirely sure I understand what you mean but I'd do something like this
<input type="select">
<?
while ($this = mysql_fetch_array($query) > 0)
{
echo "<option value=\"".$this[name]."\">".$this[name]
}
?>
</input>
I wouldn't just copy this because I haven't done something like this in a while #3
Posted 24 September 2006 - 07:15 PM
i want a drop down menu that echos all the user names in the table 'users' without me having to add them individually.
#4
Posted 24 September 2006 - 08:23 PM
Which is exactly what jake tried to give you, only he's not quite keen on his basic HTML apparently. 
Simple as that.
<select id="users">
<?php
$query = mysql_query("SELECT * FROM `users`") or die(mysql_error());
while ($users = mysql_fetch_array($query))
{
echo '<option value="'.$users['name'].'">'.$users['name'].'</option>';
}
?>
</select>
Simple as that.
Edited by Demonslay, 24 September 2006 - 08:24 PM.
#5
Posted 24 September 2006 - 08:45 PM
You have to close <option>... Hmm... I've never had a problem with that, and I never do...
And for the input part of mine all I can say is oops
I guess that's what I get for not using HTML in a while
And for the input part of mine all I can say is oops
#6
Posted 24 September 2006 - 09:41 PM
thanks, worked just fine!
#7
Posted 24 September 2006 - 11:01 PM
The close option tag is optional, I just very XHTML picky. 
Main thing you had though was the 'input' (don't know how you got that...) and you were missing a semicolon at the end of your echo command, which would throw an unexpected '}' error.
Main thing you had though was the 'input' (don't know how you got that...) and you were missing a semicolon at the end of your echo command, which would throw an unexpected '}' error.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users
