搜索分页关键字值无法传送
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,我也遇到你这种情况,搜索结果的第一页正常,显示下一页就丢失搜索结果的关键字了,我的是个信息管理系统,默认情况显示数据库所有记录,输入关键字搜索后,可正常显示第一页,但一翻页就会显示数据库所有记录,能把你搜索结果的分页代码贴出来,让我学习一下吗?
请问 楼主 我也出现 与你一样的问题 请问怎么解决呀??

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

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

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics











When you click the search field in Windows 11, the search interface automatically expands. It displays a list of recent programs on the left and web content on the right. Microsoft displays news and trending content there. Today's check promotes Bing's new DALL-E3 image generation feature, the "Chat Dragons with Bing" offer, more information about dragons, top news from the Web section, game recommendations, and the Trending Search section. The entire list of items is independent of your activity on your computer. While some users may appreciate the ability to view news, all of this is abundantly available elsewhere. Others may directly or indirectly classify it as promotion or even advertising. Microsoft uses interfaces to promote its own content,

How to use Baidu Advanced Search Baidu search engine is currently one of the most commonly used search engines in China. It provides a wealth of search functions, one of which is advanced search. Advanced search can help users search for the information they need more accurately and improve search efficiency. So, how to use Baidu advanced search? The first step is to open the Baidu search engine homepage. First, we need to open Baidu’s official website, which is www.baidu.com. This is the entrance to Baidu search. In the second step, click the Advanced Search button. On the right side of the Baidu search box, there is

How does Xianyu search for users? In the software Xianyu, we can directly find the users we want to communicate with in the software. But I don’t know how to search for users. Just view it among the users after searching. Next is the introduction that the editor brings to users about how to search for users. If you are interested, come and take a look! How to search for users in Xianyu? Answer: View details among the searched users. Introduction: 1. Enter the software and click on the search box. 2. Enter the user name and click Search. 3. Select [User] under the search box to find the corresponding user.

In the era dominated by intelligence, office software has also become popular, and Wps forms are adopted by the majority of office workers due to their flexibility. At work, we are required not only to learn simple form making and text entry, but also to master more operational skills in order to complete the tasks in actual work. Reports with data and using forms are more convenient, clear and accurate. The lesson we bring to you today is: The WPS table cannot find the data you are searching for. Why please check the search option location? 1. First select the Excel table and double-click to open it. Then in this interface, select all cells. 2. Then in this interface, click the "Edit" option in "File" in the top toolbar. 3. Secondly, in this interface, click "

The mobile Taobao app software provides a lot of good products. You can buy them anytime and anywhere, and everything is genuine. The price tag of each product is clear. There are no complicated operations at all, making you enjoy more convenient shopping. . You can search and purchase freely as you like. The product sections of different categories are all open. Add your personal delivery address and contact number to facilitate the courier company to contact you, and check the latest logistics trends in real time. Then some new users are using it for the first time. If you don’t know how to search for products, of course you only need to enter keywords in the search bar to find all the product results. You can’t stop shopping freely. Now the editor will provide detailed online methods for mobile Taobao users to search for store names. 1. First open the Taobao app on your mobile phone,

How to use JavaScript to implement table paging function? With the development of the Internet, more and more websites use tables to display data. In some cases where the amount of data is large, the data needs to be displayed in pages to improve user experience. This article will introduce how to use JavaScript to implement table paging function and provide specific code examples. 1. HTML structure First, we need to prepare an HTML structure to host tables and paging buttons. We can use <tab

MyBatis is an excellent persistence layer framework. It supports database operations based on XML and annotations. It is simple and easy to use. It also provides a rich plug-in mechanism. Among them, the paging plug-in is one of the more frequently used plug-ins. This article will delve into the principles of the MyBatis paging plug-in and illustrate it with specific code examples. 1. Paging plug-in principle MyBatis itself does not provide native paging function, but you can use plug-ins to implement paging queries. The principle of paging plug-in is mainly to intercept MyBatis

In-depth analysis of the role and usage of the static keyword in C language. In C language, static is a very important keyword, which can be used in the definition of functions, variables and data types. Using the static keyword can change the link attributes, scope and life cycle of the object. Let’s analyze the role and usage of the static keyword in C language in detail. Static variables and functions: Variables defined using the static keyword inside a function are called static variables, which have a global life cycle
