使用codeigniter php显示基于no-of视图的数据库中的所有记录


Displaying all the records from the database based on no-of views using codeigniter php

嗨,我正试图从数据库中获取基于页面视图的记录。但无法获取所有记录,只能获取一条记录。这是我的代码。

控制器:

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();。请在article()方法中使用$this->blogs_model->get_all_buzzling();,而不是在blogs控制器上使用buzzling()

<?php
function article()
{
    $data['records2'] = $this->blogs_model->get_all_buzzling();
    $data['mainpage'] = 'buzzling';
    $this->load->view('templates/template',$data);
}
?>