> 백엔드 개발 > PHP 튜토리얼 > PHP搜索结果分页显示有关问题。

PHP搜索结果分页显示有关问题。

WBOY
풀어 주다: 2016-06-13 12:27:11
원래의
6010명이 탐색했습니다.

PHP搜索结果分页显示问题。。
首页显示没问题,翻页显示数据没有。。。代码

	include_once("script/conn.php");<br />    class Page{<br />        private $curPage;//当前页面<br />        private $totalPages;//数据总共分多少页显示<br />        private $dispNum;//每页显示的数据条数<br />        private $queryStr;//查询的SQL语句<br />        private $limitStr;//查询语句后面的limit控制语句<br />		private $currentPage;//获取当前页面<br />        public function __construct($queryStr='',$dispNum=3){    <br />            $result = mysql_query($queryStr);<br />            $totalNum = mysql_num_rows($result);<br />            $this->dispNum = $dispNum;<br />			$currentPage = basename ( $_SERVER["PHP_SELF"] );	//返回路径中的文件名部分<br />            $this->totalPages = ceil($totalNum / $dispNum);<br />            $this->queryStr = $queryStr;<br />            $temp = (isset($_GET["curPage"]) ? $_GET["curPage"] : 1);<br />            $this->setCurPage($temp);<br />            $this->showCurPage();<br />            $this->showFoot();<br />        }        <br />        private function showCurPage(){<br />            $this->limitStr = ' LIMIT '.(($this->curPage - 1)* $this->dispNum).','.$this->dispNum;<br />            $result = mysql_query($this->queryStr.$this->limitStr);<br />            while($row = mysql_fetch_assoc($result)){<br />				echo "<img  src=".$row['Image']." / alt="PHP搜索结果分页显示有关问题。" >";<br />				echo "<br/>";<br />            }<br />        }<br />        private function setCurPage($curPage){<br />                if($curPage < 1){<br />                    $curPage = 1;<br />                }<br />                else if($curPage > $this->totalPages){<br />                    $curPage = $this->totalPages;<br />                }<br />                    $this->curPage = $curPage;<br />        }<br />        private function showFoot(){<br />            echo '<a href="?curPage=1">首页</a>丨';<br />            echo '<a href="?curPage='.($this->curPage - 1).'">上一页</a>丨';<br />			echo '<a href="?curPage='.($this->curPage + 1).'">下一页</a>丨';<br />            echo '<a href="?curPage='.$this->totalPages.'">尾页</a>丨';<br />			echo "共有".$this->totalPages."页丨";<br />			echo "当前第 <font color=red>".$this->curPage."</font> 页";<br />        }<br />  }<br />$keyword=$_POST['search'];<br />$sql=mysql_query("select * from didian where name like '%$keyword%'");<br />[email&#160;protected]_fetch_object($sql);<br />if(!$raw){<br />	echo "<font color='red'>您搜索的信息不存在,请使用类似的关键字进行检索!</font>";<br />}
로그인 후 복사
如果单独这样输出是没问题的。。但加上这条的话翻页就没数据显示了..这是搜索框判断条件
switch($keyword){<br />	case '桂林':$pages = new Page('SELECT * FROM `image_guilin`', 3);break;<br />	case '海南':$pages = new Page('SELECT * FROM `image_hainan`', 3);break;<br />	case '北京':$pages = new Page('SELECT * FROM `image_beijing`', 3);break;<br />	case '九寨沟':$pages = new Page('SELECT * FROM `image_jiuzhaigou`', 3);break;<br />	case '太行山':$pages = new Page('SELECT * FROM `image_taihengshan`', 3);break;<br />	case '香格里拉':$pages = new Page('SELECT * FROM `image_xianggelila`', 3);break;<br />	case '小兴安岭':$pages = new Page('SELECT * FROM `image_xiaoxinganling`', 3);break;<br />	case '西双版纳':$pages = new Page('SELECT * FROM `image_xishuangbanna`', 3);break;<br />}
로그인 후 복사

后面是html搜索框跳转
<div id="search_box"><br />		<form id="search_form" method="post" action="search.php"> <br />		<input type="text" id="search" value="城市、景点" onFocus="this.value=''"   style="max-width:90%" name="search"/><br />		<input type="submit" id="s_search" value="搜索" name="Submit" onClick="return check(form)"/><br />		</form> <br />	</div>
로그인 후 복사
不知道为什么这样。。求教。。。
------解决思路----------------------
$keyword=$_POST['search'];
1.你获取参数的名称是search,不是keyword.
2.因为分页是用的是get,所以不能获取。

改成这样就可以了
<br /><br /><?php<br />include_once("script/conn.php");<br />    class Page{<br />        private $curPage;//当前页面<br />        private $totalPages;//数据总共分多少页显示<br />        private $dispNum;//每页显示的数据条数<br />        private $queryStr;//查询的SQL语句<br />        private $limitStr;//查询语句后面的limit控制语句<br />        private $currentPage;//获取当前页面<br />        private $keyword;// 关键字<br />        public function __construct($queryStr='', $keyword='', $dispNum=3){    <br />            $result = mysql_query($queryStr);<br />            $totalNum = mysql_num_rows($result);<br />            $this->dispNum = $dispNum;<br />            $this->keyword = $keyword;<br />            $currentPage = basename ( $_SERVER["PHP_SELF"] );    //返回路径中的文件名部分<br />            $this->totalPages = ceil($totalNum / $dispNum);<br />            $this->queryStr = $queryStr;<br />            $temp = (isset($_GET["curPage"]) ? $_GET["curPage"] : 1);<br />            $this->setCurPage($temp);<br />            $this->showCurPage();<br />            $this->showFoot();<br />        }        <br />        private function showCurPage(){<br />            $this->limitStr = ' LIMIT '.(($this->curPage - 1)* $this->dispNum).','.$this->dispNum;<br />            $result = mysql_query($this->queryStr.$this->limitStr);<br />            while($row = mysql_fetch_assoc($result)){<br />                echo "<img  src=".$row['Image']." / alt="PHP搜索结果分页显示有关问题。" >";<br />                echo "<br/>";<br />            }<br />        }<br />        private function setCurPage($curPage){<br />                if($curPage < 1){<br />                    $curPage = 1;<br />                }<br />                else if($curPage > $this->totalPages){<br />                    $curPage = $this->totalPages;<br />                }<br />                    $this->curPage = $curPage;<br />        }<br />        private function showFoot(){<br />            echo '<a href="?search='.$this->keyword.'&curPage=1">首页</a>丨';<br />            echo '<a href="?search='.$this->keyword.'&curPage='.($this->curPage - 1).'">上一页</a>丨';<br />            echo '<a href="?search='.$this->keyword.'&curPage='.($this->curPage + 1).'">下一页</a>丨';<br />            echo '<a href="?search='.$this->keyword.'&curPage='.$this->totalPages.'">尾页</a>丨';<br />            echo "共有".$this->totalPages."页丨";<br />            echo "当前第 <font color=red>".$this->curPage."</font> 页";<br />        }<br />  }<br />$keyword=$_REQUEST['search'];<br />$sql=mysql_query("select * from didian where name like '%$keyword%'");<br />[email&#160;protected]_fetch_object($sql);<br />if(!$raw){<br />    echo "<font color='red'>您搜索的信息不存在,请使用类似的关键字进行检索!</font>";<br />}<br />?><br /><br />
로그인 후 복사

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿