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="/static/imghwm/default1.png" data-src=".$row['Image']." class="lazy" 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 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="/static/imghwm/default1.png" data-src=".$row['Image']." class="lazy" 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 protected]_fetch_object($sql);<br />if(!$raw){<br /> echo "<font color='red'>您搜索的信息不存在,请使用类似的关键字进行检索!</font>";<br />}<br />?><br /><br />

PHPisusedforsendingemailsduetoitsintegrationwithservermailservicesandexternalSMTPproviders,automatingnotificationsandmarketingcampaigns.1)SetupyourPHPenvironmentwithawebserverandPHP,ensuringthemailfunctionisenabled.2)UseabasicscriptwithPHP'smailfunct

The best way to send emails is to use the PHPMailer library. 1) Using the mail() function is simple but unreliable, which may cause emails to enter spam or cannot be delivered. 2) PHPMailer provides better control and reliability, and supports HTML mail, attachments and SMTP authentication. 3) Make sure SMTP settings are configured correctly and encryption (such as STARTTLS or SSL/TLS) is used to enhance security. 4) For large amounts of emails, consider using a mail queue system to optimize performance.

CustomheadersandadvancedfeaturesinPHPemailenhancefunctionalityandreliability.1)Customheadersaddmetadatafortrackingandcategorization.2)HTMLemailsallowformattingandinteractivity.3)AttachmentscanbesentusinglibrarieslikePHPMailer.4)SMTPauthenticationimpr

Sending mail using PHP and SMTP can be achieved through the PHPMailer library. 1) Install and configure PHPMailer, 2) Set SMTP server details, 3) Define the email content, 4) Send emails and handle errors. Use this method to ensure the reliability and security of emails.

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.

ThebestpracticesforsendingemailssecurelyinPHPinclude:1)UsingsecureconfigurationswithSMTPandSTARTTLSencryption,2)Validatingandsanitizinginputstopreventinjectionattacks,3)EncryptingsensitivedatawithinemailsusingOpenSSL,4)Properlyhandlingemailheaderstoa


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SublimeText3 English version
Recommended: Win version, supports code prompts!

SublimeText3 Linux new version
SublimeText3 Linux latest version
