Jump to content

drop-down menu


Ph0enix

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.