• home
  • forum
  • my
  • kt
  • download
  • Dynamic Dropdown Menu

    Author: 2007-08-24 15:42:17 From:

    Put records from your database in a drop down menu/list box. You can apply it as a navigator list box. Good for saving your webpage areas or you have many links you don't want to show all of them in your pages.

    This tutorial require 1 PHP file and 1 table of mySQL database.

    1. dynamic_menu.php
    2. Database "tutorial" and table "name_list" with 2 fields: id(auto_increment), name(varchar, 50) and put some records about 20 - 30 records into this table. (directly by phpMyAdmin)

    Dynamic Menu

    dynamic_menu.php

    Source Code
    <?
    // Connect database
    mysql_connect("localhost","","");
    mysql_select_db("tutorial");

    // If submitted, check the value of "select". If its not blank value, get the value and put it into $select.
    if(isset($select)&&$select!=""){
    $select=$_GET['select'];
    }
    ?>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    </head>
    <body>
    <form id="form1" name="form1" method="get" action="<? echo $PHP_SELF; ?> ">
    Car company :
    <select name="select">
    <option value="">--- Select ---</option>
    <?
    // Get records from database (table "name_list").
    $list=mysql_query("select * from name_list order by id asc");

    // Show records by while loop.
    while($row_list=mysql_fetch_assoc($list)){
    ?>

    <option value="<? echo $row_list['id']; ?>" <? if($row_list['id']==$select){ echo "selected"; } ?>><? echo $row_list['name']; ?></option>
    <?
    // End while loop.
    }
    ?>

    </select>
    <input type="submit" name="Submit" value="Select" />
    </form>
    <hr>
    <p>
    <?
    // If you have selected from list box.
    if(isset($select)&&$select!=""){

    // Get records from database (table "name_list").
    $result=mysql_query("select * from name_list where id='$select'");
    $row=mysql_fetch_assoc($result);
    ?>

    Information about <strong><? echo $row['name']; ?></strong> company...</p>
    <p>........................................<br>
    ........................................<br>
    ........................................
    <?
    // End if statement.
    }

    // Close database connection.
    mysql_close();
    ?>

    </p>
    </body>
    </html>


    [Download Sorce Code]

    discuss this topic to forum

    relation tutorial

    No relevant information

    Category

      Ad Management (4)
      Calendars (3)
      Chat Systems (7)
      Content Management (6)
      Cookies and Sessions (8)
      Counters (8)
      Database Related (8)
      Date and Time (9)
      Development (6)
      Discussion Boards (7)
      E Commerce (6)
      Email Systems (9)
      Error Handling (5)
      File Manipulation (10)
      Flash and PHP (4)
      Form Processing (7)
      Guestbooks (8)
      Image Manipulation (3)
      Installing PHP (5)
      Introduction to PHP (9)
      Link Indexing (6)
      Mailing List Management (8)
      Miscellaneous (10)
      Networking (6)
      News Publishing (6)
      OOP (8)
      PEAR (6)
      PHP vs Other Languages (2)
      Polls and Voting (5)
      Postcards (0)
      Randomizing (8)
      Redirection (8)
      Searching (6)
      Security (6)
      Site Navigation (7)
      User Authentication (10)
      WAP and WML (7)
      Web Fetching (0)
      Web Traffic Analysis (11)
      XML and PHP (0)

    New

    Hot