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.
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>";
}
}