codeigniter为join子句的foreach()提供的无效参数

时间:2016-09-08 06:09:33

标签: codeigniter

我在互联网上尝试了解我所知道和建议的所有内容。 但所有的时间都是假的。 请帮我... 感谢

我的错误信息是:

严重性:警告

消息:为foreach()提供的参数无效

文件名:views / index.php

行号:10

model.php

    public function getBanner()
{
    $this->db->select('album.id, album.cat_id , album.poster, album.slug, album.modify, category.id, category.name, category.slug');
    $this->db->from('album,category');
    $this->db->where('album.cat_id', 'category.id');
    $query = $this->db->get();

    if($query->num_rows() != 0)
    {
        $result = $query->result_array();

        return $result;
    }
    else
    {
        return false;
    }
}

controllers.php

$data['banner'] = $this->Fornt_model->getBanner();

showbanner.php

<section class="banner">
<div class="container">
    <div class="row">
        <div class="col-sm-12">
            <div id="myCarousel" class="carousel slide" data-ride="carousel">

                <!-- Wrapper for slides -->
                <div class="carousel-inner" role="listbox">
                    <?php $item = 1; foreach($banner as $latest_poster): $item_class = ($item == 1) ? 'item active' : 'item'; ?>
                        <div class="<?php echo $item_class; ?>">
                            <img src="<?php echo base_url('images/poster/'.$latest_poster['poster']); ?>" class="img-responsive img-thumbnail">
                            <div class="carousel-caption caption">
                                <a href="<?php echo site_url('category/bollywood/'.$latest_poster['slug']); ?>" class="box">
                                    <b class="h3"><?php echo $latest_poster['name']; ?></b>
                                    <small class="p">Exclusive AT*<?php echo substr($latest_poster['modify'], 0, 10); ?></small>
                                </a>
                            </div>
                        </div>
                    <?php $item++; endforeach; ?>
                </div>
            </div>
        </div>
    </div>
    <div class="clearfix" style="padding: 10px 0;"></div>
    <div class="row hidden-xs">
    <?php $itemto = 0; foreach($banner as $latest_poster): $item_class_active = ($itemto == 0) ? 'active' : ''; ?>
        <div class="col-sm-2 pointer" data-target="#myCarousel" data-slide-to="<?php echo $itemto; ?>"><img src="<?php echo base_url('images/poster/'.$latest_poster['poster']); ?>" class="img-responsive img-thumbnail" /></div>
    <?php $itemto++; endforeach; ?>
    </div>
</div>

2 个答案:

答案 0 :(得分:0)

我认为你的查询有问题。试试

 if($query->num_rows() != 0)
        {
            $result = $query->result_array();
            print_r($result);
        }

确保您的阵列数据可用..

答案 1 :(得分:0)

如果没有行,则front_model-&gt; getBanner()会将结果返回false。因此,您将收到错误消息。使用以下代码

 public function getBanner()
{
    $this->db->select('album.id, album.cat_id , album.poster, album.slug, album.modify, category.id, category.name, category.slug');
    $this->db->from('album,category');
    $this->db->where('album.cat_id', 'category.id');
    $query = $this->db->get();
    return $query->result_array();

}