简体   繁体   English

循环浏览类别

[英]Loop through looped categories

I have categories stored in a table and products in another. 我将类别存储在一个表中,将产品存储在另一个表中。 I have a loop to generate a bootstrap tab html layout. 我有一个循环来生成引导程序标签html布局。

There's my categories loop PHP code: 我的类别循环为PHP代码:

<ul id="myTabs" role="tablist" class="grid-construct nav nav-tabs nav-justified">
 <?php foreach($this->categories as $i => $category){
    <li role="presentation" class="">
      echo $category->alias;?>
    </li>
    }
 </ul>

I have 3 products in each category. 我在每个类别中有3个产品。 Bearing in mind I'm going for a bootstrap tab layout approach, How can i display the through products while looping into each category? 请记住,我要使用引导程序选项卡布局方法,当进入每个类别时如何显示直通产品?

You could try to join the product table in the query where you select the categories. 您可以尝试在选择类别的查询中加入产品表。 Then you can change your code to: 然后,您可以将代码更改为:

<ul id="myTabs" role="tablist" class="grid-construct nav nav-tabs nav-justified">
    <?php foreach($this->categories as $i => $category): ?>
    <li role="presentation" class="">
      <?php echo $category->alias; ?>
      <?php foreach($category->products as $product): ?>
        <?php echo $product->name; ?>
      <? endforeach; ?>
    </li>
    <?php endforeach; ?>
</ul>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM