View Full Version : drop down menu.. plz read

04-20-2003, 06:12 AM
Hello All!

Ok this is what I want to do..

I have a drop down menu on my site right. But I want the options of it to be controlled from a mySQL database.

I want it so u can have a text field in the database and that creates the options for the menu. So on each line of the text field the admin could place a:

<option value="home.html" frameload="main">- go home</option>

and then the php script would pick up the options 1 per line?

I hope i explained this right?!
Can anybody help?


04-20-2003, 11:53 AM
First, Create a table like this:

Name | Link | OrderId

With just 3 Columns.

Name: The link name,
Link: The address to goto when clicked,
OrderId: The ordernum of the items.

Call the table links

Now, for your code:

$db = mysql_connect("localhost", "user", "pass");
mysql_select_db("dbname", $db);

$get_links = "SELECT * FROM `links` ORDER BY `OrderId` ASC";
// You have an option here, the word ASC will order the items in ascending order by OrderId, so 1 would be at the top.
// Or you can replace it with DESC, which would keep the highest item number at the top, so eg: 10 would be at the top, 1 at the bottom.

$links = mysql_query($get_links);

// You can use for or while here, I will use while.

while($row = mysql_fetch_array($links))
echo '<option value="'.$row["Link"].'" frameload="main">'.$row["Name"].'</option>';

Hope this helps you. :thumbsup: