I have mysql database with two tables.categories and products.
categories
- id
- parent_id
- category_name
- image
- status
products
id
category_id
product_name
product_description
image
status
Question
Using php code how to go to the products page after the n level categories?
Below is my php code.Thats going to the subcategories.but i am confused with the condition to go to the products page.
<?php
$category_id = $_GET['id'];
# Get categories
$categories = array();
$qry = mysql_query("SELECT * FROM categories
WHERE parent_id='".$category_id."' AND status = '1'")
or die(mysql_error());
# Get totals
$qry_total = "SELECT COUNT(*) FROM categories
WHERE parent_id='".$category_id."' AND status = '1'";
$total_qry = mysql_query($qry_total) or die(mysql_error());
list($total) = mysql_fetch_array($total_qry);
?>
<!--Content Side-->
<div class="col-lg-9 col-md-12 col-sm-12 col-xs-12">
<section class="blog-container">
<div class="row clearfix">
<!--Products Post-->
<?php
while($row = mysql_fetch_array($qry))
{ if($total==0){?>
<div class="col-lg-4 col-md-6 col-sm-6 col-xs-12 blog-post wow fadeInLeft" data-wow-delay="0ms" data-wow-duration="1500ms">
<a href="<?php echo $root_path.'products.php?id='.$row['parent_id']?>">
<article class="column-inner">
<figure class="image-box">
<?php if(!empty($row['image'])) {?>
<img src="<?php echo $root_path;?>timthumb.php?src=<?php echo $root_path.@$row['image']?>&q=400&w=250&h=200&zc=2" alt="">
<?php } else{ ?>
<img src="<?php echo $root_path;?>timthumb.php?src=<?php echo $root_path."images/resource/no-photo.gif"?>&q=400&w=250&h=200&zc=2" alt="">
<?php } ?>
</figure>
<div class="lower-part">
<div class="post-title" ><h3><?php echo $row['category_name']; ?></h3></div>
</div>
</article>
</a>
</div>
<?php } else{
?>
<div class="col-lg-4 col-md-6 col-sm-6 col-xs-12 blog-post wow fadeInLeft" data-wow-delay="0ms" data-wow-duration="1500ms">
<a href="<?php echo $root_path.'product_categories.php?id='.$row['id']?>">
<article class="column-inner">
<figure class="image-box">
<?php if(!empty($row['image'])) {?>
<img src="<?php echo $root_path;?>timthumb.php?src=<?php echo $root_path.@$row['image']?>&q=400&w=250&h=200&zc=2" alt="">
<?php } else{ ?>
<img src="<?php echo $root_path;?>timthumb.php?src=<?php echo $root_path."images/resource/no-photo.gif"?>&q=400&w=250&h=200&zc=2" alt="">
<?php } ?>
</figure>
<div class="lower-part">
<div class="post-title" ><h3><?php echo $row['category_name']; ?></h3></div>
</div>
</article>
</a>
</div>
<?php } } ?>
</div>
</section>
</div>
<!--Content Side-->