|
在点下一页时显示的不是搜索条件的数据,而是全部的查询,不知道错在哪里,view中代码如下:
<center><div class="search"> <?php
echo form_open('home/search');
echo form_input('word');
echo form_submit("submit",'搜索');
echo form_close();
?> </div>
</center>
controllers中代码如下:
function search(){
$word=$this->input->post('word');
global $data;
//-----------------------------------分页----------------------------------
$page = $this->uri->segment(3);//URL第四项为页码值
echo $page;
if(empty($page)){
$page = 1;
}else if($page<1){
$page= 1;
}
else{
$page= $page;
}
$displaypg=2;//每页显示条数
$query = $this->db->query("select count(category_id) as count from category where category_name like '%$word%'");//查询数据库符合条件的数据总共有多少条记录
$result = $query->result();
$totle=$result[0]->count;//配置记录总条数
//判断是否有记录
if($totle==0){
//没有记录情况页面所需数据
$small_array[0] = "抱歉,暂时没有此相关数据";
$data['small_array'] = $small_array;
$data['pagenav'] = " 0页 ";
}else{
//有记录情况页面所需数据
$lastpg=ceil($totle/$displaypg); //最后页,也是总页数
$page=min($lastpg,$page);
$prepg=$page-1; //上一页
$nextpg=$page+1; //下一页
if($page>$lastpg){
$page=$lastpg;
}
$firstcount=($page-1)*$displaypg;//每页起始记录
//开始分页导航条代码:
$pagenav="显示第 <B>".($totle?($firstcount+1):0)."</B>-<B>".min($firstcount+$displaypg,$totle)."</B> 条记录,共 $totle 条记录<BR>";
$pagenav.=" <a href='".site_url("home/search/$word/")."'>首页</a> ";
if($prepg)
$pagenav.=" <a href='$prepg'>上一页</a> "; else $pagenav.=" 上一页 ";
if($nextpg)
$pagenav.=" <a href=".site_url("home/search/$word/$nextpg").">下一页</a> "; else $pagenav.=" 下一页 ";
$pagenav.=" <a href='$lastpg'>尾页</a> ";
$data['pagenav'] = $pagenav;//将分页导航传入视图
//获取显示查询得到的数据
if(isset ($word)){
$result = $this->db->query("SELECT * FROM category where category_name like '%$word%' limit $firstcount,$displaypg ");
if($result->num_rows() > 0){
$temp = 0;
foreach ($result->result_array() as $row)
{
$small_array[$temp] = "<tr><td id=".$row['category_id'].">".$row['category_name']."</td><td colspan=\"2\"><a href=".base_url("admins/admin_s_changge/index/f/".$row['category_id']."").">修改</a> <a href=".base_url("admins/admin_f_type_s/del/".$row['category_id']."").">删除</a> </td> </tr>";
$temp++;
}
}else{
$small_array[0] ="抱歉,暂时没有此相关数据!";
}
$data['small_array'] = $small_array;
}
$this->load->view('blogview', $data);
}
}
|
|