Jump to content


drop down menu/loop


6 replies to this topic

#1 Chris.

    Young Padawan

  • Members
  • Pip
  • 129 posts
  • Gender:Male

Posted 24 September 2006 - 06:45 PM

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?

#2 jakevfr

    Young Padawan

  • Members
  • Pip
  • 40 posts

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 :ph34r:

#3 Chris.

    Young Padawan

  • Members
  • Pip
  • 129 posts
  • Gender:Male

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 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

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. :D

<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 jakevfr

    Young Padawan

  • Members
  • Pip
  • 40 posts

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 :D I guess that's what I get for not using HTML in a while

#6 Chris.

    Young Padawan

  • Members
  • Pip
  • 129 posts
  • Gender:Male

Posted 24 September 2006 - 09:41 PM

thanks, worked just fine!

#7 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 24 September 2006 - 11:01 PM

The close option tag is optional, I just very XHTML picky. :D

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