首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >编解码器3中有选择的前置回路

编解码器3中有选择的前置回路
EN

Stack Overflow用户
提问于 2021-01-31 14:50:11
回答 1查看 737关注 0票数 1

我希望在视图中使用foreach循环显示来自模型的数据,但是在达到从类别表和类别产品循环的第二个周期之后,它就不工作了,显示空白的结果。

这里是我的数据库

我有两张有类别和产品的桌子

这里我的控制器

  • category_menu从分类表

中获取数据

  • product_category从产品联接类别中获取数据,其中category_id=product_category_id

//类别菜单$category_table =‘$category_table’;$result‘品类_菜单’= $this->Model_Data->fetch($category_table);// $category_table$result‘Product _$category_table’=

这里我的观点

代码语言:javascript
运行
复制
        <!-- 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 &gt; </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>
EN

回答 1

Stack Overflow用户

发布于 2021-02-05 10:12:59

为什么不能在查询中使左连接并简单地循环这些值?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65980468

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档