为什么小弟我的PHP翻页不能翻到下一页呀?求教

WBOY
Freigeben: 2016-06-13 12:26:58
Original
1664 Leute haben es durchsucht

为什么我的PHP翻页不能翻到下一页呀??求教
我定义了一个类来输出的  下面是类属性...最后是搜索页

include("script/conn.php");<br />    class Page{<br />        private $page;	//当前页码<br />        private $page_num;	//数据总共分多少页显示<br />        private $page_size;	//每页显示的数据条数<br />        private $sql;	//查询的SQL语句<br />        private $limit;	//查询语句后面的limit控制语句<br />	private $total_Num;	//总记录数<br />        public function __construct($sql='',$page_size=3){<br />            $result = mysql_query($sql);<br />            $this->total_Num = mysql_num_rows($result);<br />            $this->page_size = $page_size;<br />            $this->page_num = ceil($this->total_Num / $page_size);	//计算总页数<br />            $this->sql = $sql;<br />            $temp = (isset($_GET["page"]) ? $_GET["page"] : 1);	//获取当前页数<br />            $this->setpage($temp);<br />            $this->showpage();<br />            $this->showFoot();<br />        }<br />        private function showpage(){<br />            $this->limit = " LIMIT ".(($this->page - 1)* $this->page_size).",".$this->page_size;	//limit语句<br />            $result = mysql_query($this->sql.$this->limit);<br />            if (!$result){	//判断结果是否存在<br />                if ($this->page_num > 0){	//如果不存在且页数大于0<br />                    echo "查询出错"."<br>";<br />                }else{<br />                    echo "无数据"."<br>";<br />                }<br />                return;<br />            }<br />            $cols = mysql_num_rows($result);<br />            while($row = mysql_fetch_array($result)){<br />				echo "<img  src=".$row['Image']." / alt="为什么小弟我的PHP翻页不能翻到下一页呀?求教" >";<br />				echo "<br/>";<br />            }<br />        }<br />        private function setpage($page){<br />                if($page < 1){<br />                    $page = 1;<br />                }<br />                else if($page > $this->page_num){<br />                    $page = $this->page_num;<br />                }<br />                    $this->page = $page;<br />        }<br />        private function showFoot(){<br />			echo "<br/>";<br />            echo "<a href='?page=1'>首页</a>丨";<br />            echo "<a href='?page=".($this->page - 1)."'>上一页</a>丨";<br />            echo "<a href='?page=".($this->page + 1)."'>下一页</a>丨";<br />            echo "<a href='?page=".$this->page_num."'>尾页</a>丨";<br />			echo "共有".$this->page_num."页丨";<br />			echo "当前第".$this->page."页";<br />        }<br />  }
Nach dem Login kopieren

搜索页的我就给一部分吧。
//search1.php是搜索页



下面是搜索页的PHP
include("c.php");//c.php是上面的PHP程序
$keyword=$_POST['search'];
$sql=mysql_query("select * from didian where name like '%$keyword%'");
[email protected]_fetch_object($sql);
if(!$row){
echo "您搜索的信息不存在,请使用类似的关键字进行检索!";
}
if($keyword=='北京'){
$pages = new Page('SELECT * FROM `image_beijing`', 3);
}
代码就这样。。如在类中显示就可以实现翻到下一页,但到搜索页就不能翻页了,只能看到首页,一翻页就什么信息都没,我想问下是什么问题呀。。。求教~~~感谢...
------解决思路----------------------
那我要建议你重写了,把数据库操作部分从类中移去
class Page{<br />  private $page;    //当前页码<br />  private $page_num;    //数据总共分多少页显示<br />  private $page_size;    //每页显示的数据条数<br />  private $sql;    //查询的SQL语句<br />  private $total_Num;    //总记录数<br /><br />  public $limit;    //查询语句后面的limit控制语句<br /><br />  public function __construct($total=100, $page_size=3){<br />    $this->total_Num = $total;<br />    $this->page_size = $page_size;<br />    $this->page_num = ceil($this->total_Num / $page_size);    //计算总页数<br />    $temp = (isset($_GET["page"]) ? $_GET["page"] : 1);    //获取当前页数<br />    $this->setpage($temp);<br />    $this->showpage();<br />    $this->showFoot();<br />  }<br />  private function showpage(){<br />    $this->limit = " LIMIT ".(($this->page - 1)* $this->page_size).",".$this->page_size;    //limit语句<br />  }<br />  private function setpage($page){<br />    if($page < 1){<br />      $page = 1;<br />    }else if($page > $this->page_num){<br />      $page = $this->page_num;<br />    }<br />    $this->page = $page;<br />  }<br />  private function showFoot(){<br />     echo "<br/>";<br />     echo "<a href='?page=1'>首页</a>丨";<br />     echo "<a href='?page=".($this->page - 1)."'>上一页</a>丨";<br />     echo "<a href='?page=".($this->page + 1)."'>下一页</a>丨";<br />     echo "<a href='?page=".$this->page_num."'>尾页</a>丨";<br />     echo "共有".$this->page_num."页丨";<br />     echo "当前第".$this->page."页";<br />  }<br />}
Nach dem Login kopieren

Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage