Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Aug 2002
    Posts
    66
    Thanks
    2
    Thanked 0 Times in 0 Posts

    drop down menu.. plz read

    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?

    Thanks

  • #2
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

    PHP 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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •