www.webdeveloper.com
Results 1 to 3 of 3

Thread: Menu problem

  1. #1
    Join Date
    Dec 2006
    Posts
    31

    Menu problem

    I have the following problem. I want to make a two-dimensions menu (user clicks on a category and under it appears list of subcategories of this category). The problem is that I can't display the subcategories right under the selected category - it displays under the whole block of categories. How can I solve the problem?

    Here is my code:
    PHP Code:
    function ShowCats() {
    $cat=mysql_query("SELECT * FROM category ORDER by orderlist") or die ("Cant: " mysql_error());
    while(
    $rows=mysql_fetch_array($cat)) {
    echo 
    "<a class='categorie' href='index.php?go=products&catid=$rows[id]'>$rows[name]</a>";
    }
    if(isset(
    $catid)) {
    $subcat=mysql_query("SELECT * FROM subcategory WHERE category=$catid ORDER BY orderlist");
    while(
    $rows=mysql_fetch_array($subcat)) {
    echo 
    $rows['name'];
    }

    Thanks a lot.

  2. #2
    Join Date
    Dec 2006
    Location
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    I'm not sure where $catid is coming from, but assuming it's "there", this could be what you're looking for...
    PHP Code:
    <?php
    function ShowCats() {
      
    $cat=mysql_query("SELECT * FROM category ORDER by orderlist") or die ("Cant: " mysql_error());

      WHILE (
    $cat_rows=mysql_fetch_array($cat)) :
        echo 
    "<a class='categorie' href='index.php?go=products&catid=" $cat_rows['id']. "'>" $cat_rows['name'] . "</a>";
        IF (isset(
    $catid) AND $catid == $cat_row['id']) :
          
    $subcat=mysql_query("SELECT * FROM subcategory WHERE category=$catid ORDER BY orderlist");
          WHILE (
    $sub_rows=mysql_fetch_array($subcat)) :
            echo 
    $sub_rows['name'];
          ENDWHILE;
        ENDIF;
      ENDWHILE;
    }
    ?>

  3. #3
    Join Date
    Dec 2006
    Posts
    31
    NightShift58, your script doesn't show the subcategories at all.
    The $catid variable is set when a user clicks on a category. Any other thoughts about how to tell the script to open the subcategory list?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles