drop down menu

Discussion in 'PHP' started by himani, Jun 4, 2008.

  1. #1
    i have created a dropdown box by fetching values of categories from mssql database.
    so can anybody help me in doing this->
    if i select any option from drop down menu it should directly to that particular page and should display all the values under that category.
    for eg
    if i select category india it should display all the states in india
    Himani :confused:
     
    himani, Jun 4, 2008 IP
  2. Christian Little

    Christian Little Peon

    Messages:
    1,753
    Likes Received:
    80
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Add javascript code to your first drop-down menu like this:

    
    onChange="javascript: form.submit();"
    
    Code (markup):
    That probably doesn't work - you'll have to play around with it (javascript isn't my strong point).

    Then wherever the form submits to, put code like this:

    
    if($_GET["cat"]) {
      $query = "select col from (tablename) where category='" . $_GET['cat'] . "'");
      while($row = mysql_fetch_object(mysql_query($query)) {
        echo "$row->col<br />";
      }
    }
    
    PHP:
    Change "col" and "category" to the right names of course. But that code will output a simple list of whatever matches the category in the database. Once you get the data, then work on the formatting to fit your site.
     
    Christian Little, Jun 4, 2008 IP