Jump to content


Photo

drop-down menu


  • Please log in to reply
4 replies to this topic

#1 Ph0enix

Ph0enix
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts

Posted 20 May 2006 - 07:42 PM

Hi, i want to make a drop down menu that has thigs from my database in it.
I have people registering on my website so it is annoying to add them in on my own.
So how would i get everybody user_name into a drop down menu. Please help! thanks
[url=http://www.slimphoenix.com][/url]

#2 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 20 May 2006 - 08:06 PM

You can just pull the required information from your database, loop through it and create the entereies in the select box. Here's an example:
<?php
$result = mysql_query("SELECT `name`,`id` FROM `table`") or die(mysql_error());
echo "<select name='names'>";
while($row = mysql_fetch_assoc($result)) {
    echo "<option value='$row[id]'>$row[name]</option>";
}
echo "</select>";
?>


#3 Ph0enix

Ph0enix
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts

Posted 20 May 2006 - 08:40 PM

Well its sort of working.
When i put this code in it works showing the points for users..

$result = mysql_query("SELECT `points` FROM `points`") or die(mysql_error());
echo "<select name='names'>";
while($row = mysql_fetch_assoc($result)) {
echo "<option value='$row[points]'>$row[points]</option>";
}
echo "</select>";

(the table is called points)

but when i try this code it comes up with the right amount of options but they all say Array[user_name]


$result = mysql_query("SELECT `user_name` FROM `points`") or die(mysql_error());
echo "<select name='names'>";
while($row = mysql_fetch_assoc($result)) {
echo "<option value='$row[user_name]'>$row[user_name]</option>";
}
echo "</select>";

Do you know whats wrong?
[url=http://www.slimphoenix.com][/url]

#4 Ph0enix

Ph0enix
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts

Posted 21 May 2006 - 09:27 AM

[img src=\"style_emoticons/[#EMO_DIR#]/unsure.gif\" style=\"vertical-align:middle\" emoid=\":unsure:\" border=\"0\" alt=\"unsure.gif\" /]
[url=http://www.slimphoenix.com][/url]

#5 RSprinkel

RSprinkel
  • Members
  • PipPipPip
  • Advanced Member
  • 69 posts

Posted 28 May 2006 - 02:09 AM

Hi,

I am trying to use the code listed by SemiApocalyptic to suit my needs. Was wondering how I can get that info into a table using the Drop Down?

Thanks Much in Advance.
RSprinkel
A PHP/MySQL NOVICE I AM




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users