doupu7651 2015-07-21 13:48
浏览 39

点击链接时丢失列表

I am going through a tutorial and I have a sidebar with 2 sections: category and brands. When I click any item within the brands list everything works fine but when I click any item within the category list, the brands just disappear from the page, can anyone help, please?

I am using the following code:

"<li><a href='index.php?brand=$brand_id'>$brand_title</a></li>";

This works fine, but when when I use this:

"<li><a href='index.php?cat=$cat_id'>$cat_title</a></li>";

That's where I loose the brands list.

  • 写回答

1条回答 默认 最新

  • duansha7025 2015-07-21 13:54
    关注

    From the Code out of the comment you should try this,

    <?php
        echo "<li><a href='index.php?brand=" . $brand_id . "'>" . $brand_title . "</a></li>";
        echo "<li><a href='index.php?cat=" . $cat_id . "'>" . $cat_title . "</a></li>";
    ?>
    

    EDIT:

    function getBrands(){ 
        if(!isset($_GET['cat'])){ 
            global $connect; 
            $get_brands = "select * from brands"; 
            $run_brands = mysqli_query($connect, $get_brands); 
            while ($row_brands=mysqli_fetch_array($run_brands)){ 
                $brand_id = $row_brands['brand_id']; 
                $brand_title = $row_brands['brand_title']; 
                echo "<li><a href='index.php?brand=" . $brand_id . "'>" . $brand_title . "</a></li>"; 
            }
        }
    }
    

    So if you get a categorie the getBrands function do nothing. remove the if statement.

    function getBrands(){ 
           global $connect; 
           $get_brands = "select * from brands"; 
           $run_brands = mysqli_query($connect, $get_brands); 
           while ($row_brands=mysqli_fetch_array($run_brands)){ 
                $brand_id = $row_brands['brand_id']; 
                $brand_title = $row_brands['brand_title']; 
                echo "<li><a href='index.php?brand=" . $brand_id . "'>" . $brand_title . "</a></li>"; 
            }
        }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退