dont understand why categories arent collapsing

问题: So I am super confused, I am using a template and I have a side menu that shows categories, when you press on the category a drop down menu with corresponding categories re...

问题:

So I am super confused, I am using a template and I have a side menu that shows categories, when you press on the category a drop down menu with corresponding categories related to id's from initial category. When I press the category it is not giving me the desired results. When the href is clicked it gives me the results of the initial categories and not the categories corresponding with the href id that was clicked. Not sure what im doing wrong? current results with code below

<div class="catagories-menu">
  <ul id="menu-content2" class="menu-content collapse show">
    <?
     $database = new DB();
     $query = "select * from category where cat_SubCat IS NULL";//
     $rows = $database->get_results($query);
     foreach ($rows as $row)//foreach database result
     {                              
        echo"<li data-toggle='collapse' data-target='#$row[cat_Name]' class='collapsed' >
                <a href='#' id='$row[cat_ID]'>" . $row[cat_Name] . "</a>
                <ul class='sub-menu collapse' id='$row[cat_Name]'>
                    <li><a href='#'>All</a></li>";
                    $database = new DB();//creating an object from the class
                    $query2 = "select * from category where cat_SubCat=" .$row[cat_ID]."";//
                    $subs = $database->get_results($query2);
                    foreach ($subs as $sub)//foreach database result
                    {
                      echo"<li><a href='prodDetail.php?cat_ID=".$sub[cat_ID]."&cat_SubCat=".$sub[cat_SubCat]."' class='list-group-item'>" . $sub[cat_Name] . "</a></li>";
                    }
            echo"</ul>
             </li>";
     }
     ?>
  </ul>
</div>

Im looking for the null categories to print first and the ones associated to the nulls to print beneath desired reults
updated code from Khan's entry and replaced the $subs = $database->get_results($query);

with

$subs = $database->get_results($query2);
it worked partially. Code is not allowing drop down for first two categories but other categories are displaying really confused


回答1:

In sub you are using query, and not query2

foreach ($rows as $row)//foreach database result
     {                              
        echo"<li data-toggle='collapse' data-target='#$row[cat_Name]' class='collapsed' >
                <a href='#' id='$row[cat_ID]'>" . $row[cat_Name] . "</a>
                <ul class='sub-menu collapse' id='$row[cat_Name]'>
                    <li><a href='#'>All</a></li>";
                    $database2 = new DB();//creating an object from the class
                    $query2 = "select * from category where cat_SubCat=" .$row[cat_ID]."";//
                    $subs = $database2->get_results($query2);
                    foreach ($subs as $sub)//foreach database result
                    {
                      echo"<li><a href='prodDetail.php?cat_ID=".$sub[cat_ID]."&cat_SubCat=".$sub[cat_SubCat]."' class='list-group-item'>" . $sub[cat_Name] . "</a></li>";
                    }
            echo"</ul>
             </li>";
     }
  • 发表于 2019-02-23 23:20
  • 阅读 ( 169 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除