codeigniter为join子句上的foreach()提供的参数无效
我在网上把我知道的和建议都试了一遍。 但所有的时间都是假的。 请帮帮我。。。 谢谢 我的错误消息是: 严重性:警告 消息:为foreach()提供的参数无效 文件名:views/index.php 电话号码:10 model.phpcodeigniter为join子句上的foreach()提供的参数无效,codeigniter,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, categ
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>
我认为你的询问有问题。。试一试
if($query->num_rows() != 0)
{
$result = $query->result_array();
print_r($result);
}
确保数组数据可用。如果没有行,front\u model->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();
}
$banner变量中可能存在错误。每当函数返回false时,它都会显示错误消息i check data['banner']变量。它显示数组,但当在视图页面上调用时,如前所述返回false,您的错误似乎出现在index.php中,并且您正在showbanner.php内运行foreach循环。你的观点是什么?