include_once(script/conn.php); class page{ private $curpage;//当前页面 private $totalpages;//数据总共分多少页显示 private $dispnum;//每页显示的数据条数 private $querystr;//查询的sql语句 private $limitstr;//查询语句后面的limit控制语句 private $currentpage;//获取当前页面 public function __construct($querystr='',$dispnum=3){ $result = mysql_query($querystr); $totalnum = mysql_num_rows($result); $this->dispnum = $dispnum; $currentpage = basename ( $_server[php_self] ); //返回路径中的文件名部分 $this->totalpages = ceil($totalnum / $dispnum); $this->querystr = $querystr; $temp = (isset($_get[curpage]) ? $_get[curpage] : 1); $this->setcurpage($temp); $this->showcurpage(); $this->showfoot(); } private function showcurpage(){ $this->limitstr = ' limit '.(($this->curpage - 1)* $this->dispnum).','.$this->dispnum; $result = mysql_query($this->querystr.$this->limitstr); while($row = mysql_fetch_assoc($result)){ echo ; echo
; } } private function setcurpage($curpage){ if($curpage $this->totalpages){ $curpage = $this->totalpages; } $this->curpage = $curpage; } private function showfoot(){ echo '首页丨'; echo 'curpage - 1).'>上一页丨'; echo 'curpage + 1).'>下一页丨'; echo 'totalpages.'>尾页丨'; echo 共有.$this->totalpages.页丨; echo 当前第 .$this->curpage. 页; } }$keyword=$_post['search'];$sql=mysql_query(select * from didian where name like '%$keyword%');$raw=@mysql_fetch_object($sql);if(!$raw){ echo 您搜索的信息不存在,请使用类似的关键字进行检索!;}
如果单独这样输出是没问题的。。但加上这条的话翻页就没数据显示了..这是搜索框判断条件
switch($keyword){ case '桂林':$pages = new page('select * from `image_guilin`', 3);break; case '海南':$pages = new page('select * from `image_hainan`', 3);break; case '北京':$pages = new page('select * from `image_beijing`', 3);break; case '九寨沟':$pages = new page('select * from `image_jiuzhaigou`', 3);break; case '太行山':$pages = new page('select * from `image_taihengshan`', 3);break; case '香格里拉':$pages = new page('select * from `image_xianggelila`', 3);break; case '小兴安岭':$pages = new page('select * from `image_xiaoxinganling`', 3);break; case '西双版纳':$pages = new page('select * from `image_xishuangbanna`', 3);break;}
后面是html搜索框跳转
不知道为什么这样。。求教。。。
回复讨论(解决方案) 翻页你没有把keyword参数带过去。
private function showfoot(){
echo '首页丨';
echo 'curpage - 1).'>上一页丨';
echo 'curpage + 1).'>下一页丨';
echo 'totalpages.'>尾页丨';
echo 共有.$this->totalpages.页丨;
echo 当前第 .$this->curpage. 页;
}
这里要加上keyword参数传递。
echo 'curpage - 1).'>上一页丨';
翻页你没有把keyword参数带过去。
private function showfoot(){
echo '首页丨';
echo 'curpage - 1).'>上一页丨';
echo 'curpage + 1).'>下一页丨';
echo 'totalpages.'>尾页丨';
echo 共有.$this->totalpages.页丨;
echo 当前第 .$this->curpage. 页;
}
这里要加上keyword参数传递。
echo 'curpage - 1).'>上一页丨';
依然没数据呢
首页没参数怎么办?这是首页的http://localhost:808/web/search.php
这是第二页的http://localhost:808/web/search.php?curpage=&curpage=2
表单的action不用加什么吗?我按你的改了 private function showfoot(){ echo '首页丨'; echo 'curpage - 1).'>上一页丨'; echo 'curpage + 1).'>下一页丨'; echo 'totalpages.'>尾页丨'; echo 共有.$this->totalpages.页丨; echo 当前第 .$this->curpage. 页; }
$keyword 并没有传入 showfoot,当然是不行的
$keyword 并没有传入 showfoot,当然是不行的
那又该如何改才好呢?不知道哪改好。。
至少需要这样
echo '上一页丨'; echo 'curpage + 1).'>下一页丨'; echo 'totalpages.'>尾页丨'; echo 共有.$this->totalpages.页丨; echo 当前第 .$this->curpage. 页; }
你这个方法不能获取到$keyword,所以为空。
改成这样,加个参数
dispnum = $dispnum; $this->keyword = $keyword; $currentpage = basename ( $_server[php_self] ); //返回路径中的文件名部分 $this->totalpages = ceil($totalnum / $dispnum); $this->querystr = $querystr; $temp = (isset($_get[curpage]) ? $_get[curpage] : 1); $this->setcurpage($temp); $this->showcurpage(); $this->showfoot(); } private function showcurpage(){ $this->limitstr = ' limit '.(($this->curpage - 1)* $this->dispnum).','.$this->dispnum; $result = mysql_query($this->querystr.$this->limitstr); while($row = mysql_fetch_assoc($result)){ echo ; echo
; } } private function setcurpage($curpage){ if($curpage $this->totalpages){ $curpage = $this->totalpages; } $this->curpage = $curpage; } private function showfoot(){ echo 'keyword.'&curpage=1>首页丨'; echo 'keyword.'&curpage='.($this->curpage - 1).'>上一页丨'; echo 'keyword.'&curpage='.($this->curpage + 1).'>下一页丨'; echo 'keyword.'&curpage='.$this->totalpages.'>尾页丨'; echo 共有.$this->totalpages.页丨; echo 当前第 .$this->curpage. 页; } }$keyword=$_post['search'];$sql=mysql_query(select * from didian where name like '%$keyword%');$raw=@mysql_fetch_object($sql);if(!$raw){ echo 您搜索的信息不存在,请使用类似的关键字进行检索!;}?>
调用时需要加参数。
$pages = new page('select * from `image_guilin`', $keyword, 3);
调用时需要加参数。
$pages = new page('select * from `image_guilin`', $keyword, 3);
还是不行耶。。我搜索出来的首页没带后缀参数http://localhost:808/web/search.php一直这个状态
至少需要这样
echo 'keyword = $keyword; $currentpage = basename ( $_server[php_self] ); //返回路径中的文件名部分 $this->totalpages = ceil($totalnum / $dispnum); $this->querystr = $querystr; $temp = (isset($_get[curpage]) ? $_get[curpage] : 1); $this->setcurpage($temp); $this->showcurpage(); $this->showfoot(); } private function showcurpage(){ $this->limitstr = ' limit '.(($this->curpage - 1)* $this->dispnum).','.$this->dispnum; $result = mysql_query($this->querystr.$this->limitstr); while($row = mysql_fetch_assoc($result)){ echo ; echo
; } } private function setcurpage($curpage){ if($curpage $this->totalpages){ $curpage = $this->totalpages; } $this->curpage = $curpage; } private function showfoot(){ echo 'keyword.'&curpage=1>首页丨'; echo 'keyword.'&curpage='.($this->curpage - 1).'>上一页丨'; echo 'keyword.'&curpage='.($this->curpage + 1).'>下一页丨'; echo 'keyword.'&curpage='.$this->totalpages.'>尾页丨'; echo 共有.$this->totalpages.页丨; echo 当前第 .$this->curpage. 页; } }$keyword=$_request['search'];$sql=mysql_query(select * from didian where name like '%$keyword%');$raw=@mysql_fetch_object($sql);if(!$raw){ echo 您搜索的信息不存在,请使用类似的关键字进行检索!;}?>
$keyword=$_post['search'];
1.你获取参数的名称是search,不是keyword.
2.因为分页是用的是get,所以不能获取。
改成这样就可以了
dispnum = $dispnum; $this->keyword = $keyword; $currentpage = basename ( $_server[php_self] ); //返回路径中的文件名部分 $this->totalpages = ceil($totalnum / $dispnum); $this->querystr = $querystr; $temp = (isset($_get[curpage]) ? $_get[curpage] : 1); $this->setcurpage($temp); $this->showcurpage(); $this->showfoot(); } private function showcurpage(){ $this->limitstr = ' limit '.(($this->curpage - 1)* $this->dispnum).','.$this->dispnum; $result = mysql_query($this->querystr.$this->limitstr); while($row = mysql_fetch_assoc($result)){ echo ; echo
; } } private function setcurpage($curpage){ if($curpage $this->totalpages){ $curpage = $this->totalpages; } $this->curpage = $curpage; } private function showfoot(){ echo 'keyword.'&curpage=1>首页丨'; echo 'keyword.'&curpage='.($this->curpage - 1).'>上一页丨'; echo 'keyword.'&curpage='.($this->curpage + 1).'>下一页丨'; echo 'keyword.'&curpage='.$this->totalpages.'>尾页丨'; echo 共有.$this->totalpages.页丨; echo 当前第 .$this->curpage. 页; } }$keyword=$_request['search'];$sql=mysql_query(select * from didian where name like '%$keyword%');$raw=@mysql_fetch_object($sql);if(!$raw){ echo 您搜索的信息不存在,请使用类似的关键字进行检索!;}?>
嗯 可以了 真是感激不尽!!
