Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
Thread: drop down menu.. plz read
04-20-2003, 05:12 AM #1
- Join Date
- Aug 2002
- Thanked 0 Times in 0 Posts
drop down menu.. plz read
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, 10:53 AM #2
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");
$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>';