您好我正在尝试根据页面的无视图从数据库中获取记录。但是无法获取只获得一条记录的所有记录。这是我的代码。
控制器:
function buzzling()
{
$data['records2'] = $this->blogs_model->get_all_buzzling();
$data['mainpage'] = 'buzzling';
$this->load->view('templates/template',$data);
}
型号:
function get_all_buzzling()
{
$this->db->select('B.*');
$this->db->from('blogs AS B');
$this->db->where(array('B.status'=>1));
$this->db->order_by("ne_views", "asc");
$q=$this->db->get();
if($q->num_rows()>0)
{
return $q->result();
}
else
{
return false;
}
}
查看:
<div class="right">
<?php if(isset($records2) && is_array($records2)):?>
<?php foreach ($records2 as $r):?>
<h1 class="headline2"><span class="headline">Buzzing</span></h1>
<div class="clearfix float-my-children">
<img src="<?php echo base_url();?>admin/images/blogimages/thumbs/<?php echo $r->image_path;?>" width=100>
<div class="blogclasstext1"><?php echo $r->description;?></div>
</div>
<?php endforeach ; endif;?>
</div>
示例数据库表
blog_id image description status ne_views
1 image.png description 1 3
2 image.png description 1 2
3 image.png description 1 4
4 image.png description 1 1
答案 0 :(得分:0)
您在另一种方法中呼叫$this->blogs_model->get_all_buzzling();
。
请在$this->blogs_model->get_all_buzzling();
控制器上使用article()
方法而不是buzzling()
使用blogs
。
<?php
function article()
{
$data['records2'] = $this->blogs_model->get_all_buzzling();
$data['mainpage'] = 'buzzling';
$this->load->view('templates/template',$data);
}
?>