|
PHP复制代码
function _pagelist ($method, $total, $perpage=3) {
$config['base_url'] = base_url () . 'index.php/' . 'Yumaoqiu/' . $method . '/';
$config['total_rows'] = $total;
$config['per_page'] = $perpage;
$config['next_link'] = '下一页';
$config['prev_link'] = '上一页';
return $config;
}
function _news_list ($id) {
$this->load->model('Shu');
$this->load->library('pagination'); //载入分页类
//$rows = $this->db->count_all_results();
$query_num=$this->db->query('SELECT * FROM liao_news WHERE c_id='."$id".'');
//rows=10;
[color =Red ]这里为什么取不到多少条 ,找不出是哪个地方出错 [/color ]
$rows = (int ) $query_num->num_rows(); //总条数 .
//echo $rows;
$rows=4;
$conf = $this->_pagelist ('huodong', $rows); //分页配置方法
$this->pagination->initialize($conf); //把配置传给分页类
$offset = (int ) $this->uri->segment(3);
//这句我加了查询条件,分页不显示 where c_id=125
$sql = "SELECT * FROM liao_news limit ?,? ;";
$result = $this->db->query($sql, array($offset, $conf['per_page']));
// print_r($result->result_array());
return $result;
}
function huodong ($id=125) {
$this->load->model('Shu');
$data['result'] = $this->_news_list ($id);
$data['head'] = 'head';
$data['left'] = 'left';
$data['foot'] = 'foot';
$data['news_list'] = $this->Shu->news_list(128);
// print_r($data['news_list']);
$this->load->view('huodong', $data);
}
复制代码
这是视图页
HTML复制代码 <div id="yumaoqiu">
<?php $this->load->view($head); ?>
<div class="main">
<?php $this->load->view($left); ?>
<div class="huodong f_main">
<dl>
<dt><img src="images/f_huodong.jpg"/></dt>
<?php
foreach($result->result_array() as $rs){
?>
<dd><a href=""><?php echo $rs['title'];?></a></dd>
<?php
}
?>
</dl>
<div class="pagelist">
<?php echo $this->pagination->create_links();?>
</div>
</div>
</div>
<?php $this->load->view($foot); ?>
</div> 复制代码
帮忙看下.谢谢了 |
|