我希望在视图中使用foreach循环显示来自模型的数据,但是在达到从类别表和类别产品循环的第二个周期之后,它就不工作了,显示空白的结果。
这里是我的数据库
我有两张有类别和产品的桌子
这里我的控制器
中获取数据
//类别菜单$category_table =‘$category_table’;$result‘品类_菜单’= $this->Model_Data->fetch($category_table);// $category_table$result‘Product _$category_table’=
这里我的观点
<!-- Category -->
<section class="category-bg">
<div class="container">
<?php
$i = 1;
foreach ($category_menu as $category_row) {
?>
<div class="landing-header">
<div class="landing-header-wrapper">
<div class="landing-header-left">
<h1><?php echo $category_row->category_name ?></h1>
</div>
<div class="landing-header-right text-right">
<a href="<?php echo base_url('category/'.str_replace(' ', '-', strtolower($category_row->category_name))) ?>">Lihat semua > </a>
</div>
</div>
</div>
<div class="landing-body">
<!-- Product Swiper -->
<div class="swiper-container swiper-product">
<div class="swiper-wrapper">
<?php
foreach ($product_category as $product_category_row) if ($product_category_row->product_category_id === $category_row->category_id) {
echo ''.$i.',';
echo ''.$category_row->category_id.',';
echo ''.$product_category_row->product_category_id;
?>
<!-- Product -->
<div class="swiper-slide">
<a href="<?php echo base_url('product/'.str_replace(' ', '-', strtolower($product_category_row->product_name))) ?>">
<div class="landing-card">
<div class="landing-card-header">
<img src="<?php echo base_url('assets/img/product/'.$product_category_row->product_image) ?>">
</div>
<div class="landing-card-body">
<div class="landing-card-title">
<h1><?php echo $product_category_row->product_name ?></h1>
</div>
<div class="landing-card-sold">
<span>Terjual <?php echo $product_category_row->product_sold ?></span>
</div>
<div class="landing-card-old-price text-right">
<span class="strike">Rp <?php echo number_format($product_category_row->product_sell_price, 0, ",", ".") ?></span>
</div>
<div class="landing-card-price">
<span class="flex-price-discount text-center">- 20%</span>
<span class="flex-price-display text-center">Rp <?php echo number_format($product_category_row->product_sell_price, 0, ",", ".") ?></span>
</div>
</div>
</div>
</a>
</div>
<?php
}
?>
<!-- All Product -->
<div class="swiper-slide">
<a href="<?php echo base_url('category/'.str_replace(' ', '-', strtolower($category_row->category_name))) ?>">
<div class="landing-card">
<div class="landing-card-header">
<img src="<?php echo base_url('assets/img/product/default.jpg') ?>">
</div>
<div class="landing-card-body">
<strong>Lihat <?php echo count($category_row) ?>+</strong> Barang Lainnya di <?php echo $category_row->category_name ?>
</div>
</div>
</a>
</div>
</div>
<!-- Add Pagination -->
<div class="swiper-pagination swiper-pagination-product"></div>
</div>
</div>
<?php
}
$i++;
?>
</div>
</section>
发布于 2021-02-05 10:12:59
为什么不能在查询中使左连接并简单地循环这些值?
https://stackoverflow.com/questions/65980468
复制相似问题