使用php

时间:2015-12-12 10:07:15

标签: php mysql

我有两个tables.categories和产品的mysql数据库。

类别

  1. ID
  2. PARENT_ID
  3. CATEGORY_NAME
  4. 图像
  5. 状态
  6. 产品

    1. ID

    2. CATEGORY_ID

    3. PRODUCT_NAME

    4. PRODUCT_DESCRIPTION

    5. 图像

    6. 状态

    7. 问题 使用php代码如何在n级别类别之后转到产品页面? 下面是我的PHP代码。有什么去了子类别。但是我对进入产品页面的条件感到困惑。

      <?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-->
      

0 个答案:

没有答案