您好,我正在尝试根据页面的浏览次数从数据库中获取记录。但是无法获取仅获取一条记录的所有记录。这是我的代码。
Controller :
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
最佳答案
您在另一个方法中调用了 $this->blogs_model->get_all_buzzling();
。
请在 blogs< 上的
Controller 。 article()
方法中使用 $this->blogs_model->get_all_buzzling();
,而不是 buzzling()
/
<?php
function article()
{
$data['records2'] = $this->blogs_model->get_all_buzzling();
$data['mainpage'] = 'buzzling';
$this->load->view('templates/template',$data);
}
?>
关于php - 使用 codeigniter php 基于无 View 显示数据库中的所有记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40395032/