SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    Web Enthusiast
    Join Date
    Jul 2000
    Location
    Western Massachusetts, USA
    Posts
    1,389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    need script for db driven drop-down menu

    I want to create a horizontal series of drop-down menus whose sub-items are db driven. Here is the PHP script for one of the menu items in the series.
    PHP Code:
    <ul>
      <li><a href="#">programs</a> 
        <ul>
          <?php
    //navigation to program categories 11/26/07
    $links_prog_cats = @mysql_query("SELECT DISTINCT id, name FROM category_programs WHERE site_id='$site_id' AND visible = 'Y' ORDER BY order_cat"); 
    if (!
    $links_prog_cats) {
      exit(
    '<p>Error retrieving links from database!<br />'.
          
    'Error: ' mysql_error() . '</p>');
        }
    //end if !links
    while ($prog_cat mysql_fetch_array($links_prog_cats)) {
      
    $c_id $prog_cat['id'];
      
    $name_cat htmlspecialchars($prog_cat['name_cat']);
      echo 
    "<li>";
      echo 
    "<a href='cat_prog/$site_address/$c_id'>$name_cat</a></li>;\n";
      }
    //end while categories
      
    ?>
        </ul>
      </li>
    </ul>
    Suggestions?
    Last edited by paulcj2; Nov 26, 2007 at 19:38. Reason: additional info
    Paul C.
    ClickBasics
    http://www.clickbasics.com

  2. #2
    SitePoint Evangelist priti's Avatar
    Join Date
    Aug 2006
    Location
    India
    Posts
    488
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paulcj2 View Post
    I want to create a horizontal series of drop-down menus whose sub-items are db driven. Here is the PHP script for one of the menu items in the series.
    PHP Code:
    <ul>
      <li><a href="#">programs</a> 
        <ul>
          <?php
    //navigation to program categories 11/26/07
    $links_prog_cats = @mysql_query("SELECT DISTINCT id, name FROM category_programs WHERE site_id='$site_id' AND visible = 'Y' ORDER BY order_cat"); 
    if (!
    $links_prog_cats) {
      exit(
    '<p>Error retrieving links from database!<br />'.
          
    'Error: ' mysql_error() . '</p>');
        }
    //end if !links
    while ($prog_cat mysql_fetch_array($links_prog_cats)) {
      
    $c_id $prog_cat['id'];
      
    $name_cat htmlspecialchars($prog_cat['name_cat']);
      echo 
    "<li>";
      echo 
    "<a href='cat_prog/$site_address/$c_id'>$name_cat</a></li>;\n";
      }
    //end while categories
      
    ?>
        </ul>
      </li>
    </ul>
    Suggestions?
    you can do this will ajax .

    1.populate the first dropdown
    2.onchange of dropdown1 query db and get the results.

    in javascript you need to create dynamic select.

    just for example

    test.html
    <select name='country'></select>


    test.js
    $str='country1,country2,country3';
    split this string
    then in for loop creation option
    option= new option(text,value);

    that str can be filled from php logic.

    number of examples will be avialabel.I have done smiliar thing number of time. :-)
    hope it helps. !!


Bookmarks

Posting Permissions

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