ci分页

本文介绍了一个使用CodeIgniter框架实现新闻列表分页显示的例子。通过定义控制器News_list并调用模型n中的news_list方法来获取数据,然后使用分页库进行分页操作,最终加载视图news_list_lm进行数据显示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

调用视图newslist页面

控制器news_list

class News_list extends CI_Controller{
 var $base;
 var $base_admin;
 function News_list(){
  parent::__construct();
  $this->base=$this->config->item('base_url');
  $this->base_admin=$this->base.'admin/';
 }
 function index(){
  $data['base']=$this->base;
  $data['base_admin']=$this->base_admin;
  $this->load->model('n');
  $rows=$this->n->index();  //×?????
  $this->load->library('pagination');
  $config['base_url'] = $this->base.'/m/news_list/index';
  $config['total_rows'] = $rows;
  $config['per_page'] = '1';
  $config['uri_segment']='4';
  $this->pagination->initialize($config);
  $data['page']=$this->pagination->create_links();
  //load the model and get results
  $data['results'] = $this->n->news_list($this->uri->segment(4),$config['per_page']);
  $this->load->view('admin/news_list_lm',$data);

 
 }
 
 }

 

从模型n文件中news_list方法中传进参数,模型中接受参数并分页显示。

 function news_list($num,$offset){
  $base=$this->config->item('base_url');
  if($num==""){
   $num=0;
  }
   $sql="select *,(select news_class_title from news_class where news_class_id=news.news_class_id) as news_class_title from news order by newsid desc limit $num , $offset ";
         $query=$this->db->query($sql);
   $list=" ";
   foreach($query->result() as $row){
    $list=$list.'$row->newstime.';
   }
  
   return $list;
 }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值