search.php
<?phpinclude('db_class.php'); include('inc/function.php'); $keyword=trim($_POST['keyword']);if($keyword==""){echo "<script>alert('请输入新闻名称!'); history.go(-1);</script>";exit;//结束程序}// 数据库查找代码$page=isset($_POST['page'])?intval($_POST['page']):1; $num=2; $total=$db->getcount("select * from `".$prefix."newsbase` where id like '%{$keyword}%' or title like '%{$keyword}%' ");//页码计算$pagenum=ceil($total/$num); //获得总页数,也是最后一页$page=min($pagenum,$page);//获得首页$prepg=$page-1;//上一页$nextpg=($page==$pagenum ? 0 : $page+1);//下一页$offset=($page-1)*$num;$result=$db->query("select * from `".$prefix."newsbase` where sn like '%{$keyword}%' or title like '%{$keyword}%' or author like '%{$keyword}%' order by news_id desc");if($row=mysql_num_rows($result)){while($row=$db->getarray($result)){?><tr> <td class="font" valign="top" width="130"><?php echo $row[id]; ?></td> <td class="font" valign="top" width="130"><?php echo $row[title]; ?></td> <td class="font" valign="top" width="130"><?php echo $row[author]; ?></td></tr> <?php}} else{echo "<script>alert('没有该新闻信息!'); history.go(-1);</script>";exit;//结束程序}?><?php include 'inc/fy.php'; //分页类$page=new page(array('total'=>$total,'perpage'=>$num));echo $page->show(3);?>
'inc/fy.php' 是网上找的一个PHP分页类(支持四种分页模式),这里我使用的是模式三,现在的问题是搜索正确显示,但是在分页单击下一页的时候老提示“请输入新闻名称”,也就是说关键字没传成功,是在不明白问题在哪里,在论坛上搜索了好久都没有类似的问题,特来请教各位大虾!
回复讨论(解决方案)
1. 你的page变量不是用get传递吗。
2.$result=$db->query("select * from `".$prefix."newsbase` where sn like '%{$keyword}%' or title like '%{$keyword}%' or author like '%{$keyword}%' order by news_id desc"); 这句没有传递分页条件。
改为:
$result=$db->query("select * from `".$prefix."newsbase` where sn like '%{$keyword}%' or title like '%{$keyword}%' or author like '%{$keyword}%' order by news_id desc Limit {$offset},{$num}");
已经page改成get传递,同时增加传递分页条件,可以实现了搜索后按照$num的值来显示每页的条数,但是在单击下一页的时候还是进不了下一页,提示“请输入新闻名称”
那你的url可能有问题。。你分页类中有url吗?上一页,下一页,。。。都需要有url的。
我觉得应该没有问题,因为在做新闻列表的时候这个分页类是成功的,但是在做这次的搜查列表的时候分页就出现问题了,查了好久,也没发现问题,
http://www.chinahtml.com/0702/php-117150834711176.html
这个就是我参考的分页类,我使用的是model(3),
琢磨了两天了,一点头绪都没有,所以麻烦各位大虾帮忙分析分析!
今天再次测试将下面这段搜索代码删除后,点击搜索出来的是数据库中全部的数据,分页也能正常显示,但是加上下面这段代码后,单击下一页时老提示“请输入新闻名称”,造成错误的应该不是URL!搞不懂!?
$keyword=trim($_POST['keyword']);if($keyword==""){echo "<script>alert('请输入新闻名称!'); history.go(-1);</script>";exit;//结束程序}
$_POST['keyword'] 只在表单提交时有效,翻页后就没有了
传递分页里面的关键字的话,最好在表单里面使用GET方式提交。提交之后,表单里面的Action里面的链接带的所有参数将不会自动被提交。必须放到里面才可以。其次是,遇到中文的问题,必须进行url_encode编码才能进行传递。不然会乱码。 http://www.phpcxz.com/a/web/phpweb/2011/0802/113.html
按照大家提出的质疑解决了问题,非常感谢各位朋友!
可以在翻页的地方加上 .php?keyword=$keyword传递keyword参数
然后在页面上加上$keyword=isset($_POST['keword'])?'':(isset($_GET['keyword'])?$_GET['keyword']:'').
是的,已经解决,当解决问题后回过头来发现这个问题真的很简单,惭愧,基础有待加强,呵呵!
LZ,我也遇到你这种情况,搜索结果的第一页正常,显示下一页就丢失搜索结果的关键字了,我的是个信息管理系统,默认情况显示数据库所有记录,输入关键字搜索后,可正常显示第一页,但一翻页就会显示数据库所有记录,能把你搜索结果的分页代码贴出来,让我学习一下吗?
请问 楼主 我也出现 与你一样的问题 请问怎么解决呀??

Thedifferencebetweenunset()andsession_destroy()isthatunset()clearsspecificsessionvariableswhilekeepingthesessionactive,whereassession_destroy()terminatestheentiresession.1)Useunset()toremovespecificsessionvariableswithoutaffectingthesession'soveralls

Stickysessionsensureuserrequestsareroutedtothesameserverforsessiondataconsistency.1)SessionIdentificationassignsuserstoserversusingcookiesorURLmodifications.2)ConsistentRoutingdirectssubsequentrequeststothesameserver.3)LoadBalancingdistributesnewuser

PHPoffersvarioussessionsavehandlers:1)Files:Default,simplebutmaybottleneckonhigh-trafficsites.2)Memcached:High-performance,idealforspeed-criticalapplications.3)Redis:SimilartoMemcached,withaddedpersistence.4)Databases:Offerscontrol,usefulforintegrati

Session in PHP is a mechanism for saving user data on the server side to maintain state between multiple requests. Specifically, 1) the session is started by the session_start() function, and data is stored and read through the $_SESSION super global array; 2) the session data is stored in the server's temporary files by default, but can be optimized through database or memory storage; 3) the session can be used to realize user login status tracking and shopping cart management functions; 4) Pay attention to the secure transmission and performance optimization of the session to ensure the security and efficiency of the application.

PHPsessionsstartwithsession_start(),whichgeneratesauniqueIDandcreatesaserverfile;theypersistacrossrequestsandcanbemanuallyendedwithsession_destroy().1)Sessionsbeginwhensession_start()iscalled,creatingauniqueIDandserverfile.2)Theycontinueasdataisloade

Absolute session timeout starts at the time of session creation, while an idle session timeout starts at the time of user's no operation. Absolute session timeout is suitable for scenarios where strict control of the session life cycle is required, such as financial applications; idle session timeout is suitable for applications that want users to keep their session active for a long time, such as social media.

The server session failure can be solved through the following steps: 1. Check the server configuration to ensure that the session is set correctly. 2. Verify client cookies, confirm that the browser supports it and send it correctly. 3. Check session storage services, such as Redis, to ensure that they are running normally. 4. Review the application code to ensure the correct session logic. Through these steps, conversation problems can be effectively diagnosed and repaired and user experience can be improved.

session_start()iscrucialinPHPformanagingusersessions.1)Itinitiatesanewsessionifnoneexists,2)resumesanexistingsession,and3)setsasessioncookieforcontinuityacrossrequests,enablingapplicationslikeuserauthenticationandpersonalizedcontent.


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

SublimeText3 Chinese version
Chinese version, very easy to use

Notepad++7.3.1
Easy-to-use and free code editor

Zend Studio 13.0.1
Powerful PHP integrated development environment

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

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.
