CI框架对某个条件查询的结果的分页显示
本帖最后由 knight、 于 2016-8-3 16:09 编辑</head><body>
<div>
<table width="500px">
<tr>
<th>ID号</th>
<th>编写者姓名</th>
<th>新闻标题</th>
<th>新闻内容</th>
<th>上传时间</th>
</tr>
<?php foreach ($selectList as $item): ?><tr style="text-align:center;">
<td><?php echo $item['id'] ?></td>
<td><?php echo $item['name'] ;?></td>
<td><?php echo $item['title'] ;?></td>
<td><?php echo $item['news'] ;?></td>
<td><?php echo $item['savetime'] ;?></td>
<td><a href = "\show_news/del/<?php echo $item['id'] ?>">删除</a></td>
<td><a href = "\show_news/modify/<?php echo $item['id'] ?>">修改</a></td>
</tr>
<?php endforeach; ?></table>
<form action="/show_news/select" method="get" name="s" accept-charset="utf-8" />
按编写者查询<input type = "text" name = "xm">
按标题查询<input type = "text" name = "bt">
按新闻查询<input type = "text" name = "xw">
按时间查询<input type = "text" name = "sj">
<input type="submit" name="submit" value="查询" />
</form>
<a href = "/show_news/index">回到首页</a></br>
</div>
</body>
</html>上面是视图,提交查询条件的function select() { $query = $this->show_news_model->select();
//将结果集作为关联数组返回
$data['selectList'] = $query;
$this->load->view('select',$data);
}上面是控制器方法,来调用下面的模型 function select() {
$this->load->database();
parse_str($_SERVER['QUERY_STRING'], $_GET);
$data['xm'] = $this->input->get('xm');
$data['bt'] = $this->input->get('bt');
$data['xw'] = $this->input->get('xw');
$data['sj'] = $this->input->get('sj');
// $data['xm'] = "knight";
// $data['bt'] = $this->input->get('bt');
// $data['xw'] = $this->input->get('xw');
// $data['sj'] = $this->input->get('sj');
echo 'data';
var_dump($data);
$info = array();
if($data['xm'] != '') {
$info['name'] = $data['xm'];
}
if($data['bt'] != '') {
$info['title'] = $data['bt'];
}
if($data['xw'] != '') {
$info['news'] = $data['xw'];
}
if($data['sj'] != '') {
$info['savetime'] = $data['sj'];
}
// $info = array('name' => $data['xm'],'title' => $data['bt'],'news' => $data['xw'],'savetime' => $data['sj']);
$this->db->where($info);
$this->db->select("*");
$result = $this->db->get('news')->result_array();
echo $this->db->last_query();
return $result;
}
现在的问题就是对这个查询的结果进行分页应该怎么写呢。求大神指点
页:
[1]