Jump to content

Archived

This topic is now archived and is closed to further replies.

Ph0enix

drop-down menu

Recommended Posts

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

Share this post


Link to post
Share on other sites
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:
[code]<?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>";
?>[/code]

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
[img src=\"style_emoticons/[#EMO_DIR#]/unsure.gif\" style=\"vertical-align:middle\" emoid=\":unsure:\" border=\"0\" alt=\"unsure.gif\" /]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.