Search. php & lt ;? Phpinclude (db_class.php); & nbsp; include (incfunction. php); & nbsp; $ keywordtrim ($ _ POST [keyword]); if ($ keyword) {echo & nbsp; & lt; s search page keyword value cannot be transferred
Search. php
Include ('Db _ class. php ');
Include ('Inc/function. php ');
$ Keyword = trim ($ _ POST ['keyword']);
If ($ keyword = ""){
Echo "script" alert ('Enter the News name! '); History. go (-1); script ";
Exit; // end the program
}
// Database search code
$ 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} % '");
// Page number calculation
$ Pagenum = ceil ($ total/$ num); // obtain the total number of pages, which is also the last page.
$ Page = min ($ pagenum, $ page); // Get the homepage
$ Prepg = $ page-1; // Previous page
$ Nextpg = ($ page = $ pagenum? 0: $ page + 1); // Next page
$ 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 )){
?>
}
} Else {
Echo "script" alert ('no news! '); History. go (-1); script ";
Exit; // end the program
}
?>
Include 'Inc/fy. php'; // paging class
$ Page = new page (array ('total' => $ total, 'perpage' => $ num ));
Echo $ page-> show (3 );
?>
'Inc/fy. php' is a php paging class found on the Internet (four paging modes are supported). here I am using Mode 3. the problem is that the search is correctly displayed, however, when you click the next page on the page, you will always be prompted "Enter the News name". that is to say, if the keyword fails to be passed, you cannot understand the problem, I have searched the forum for a long time and have no such problems. I would like to ask you about prawns!
------ Solution --------------------
1. isn't your page variable passed with 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 "); this statement does not pass paging conditions.
Changed:
$ 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 }");
------ Solution --------------------
$ _ POST ['keyword'] is valid only when the form is submitted. after turning the page, there will be no more
------ Solution --------------------
If you want to pass the keywords in the page, it is best to use the GET method in the form for submission. After submission, all the parameters contained in the link in the Action in the form will not be automatically submitted. Must be placed . Second, in the case of Chinese characters, url_encode must be used for transmission. Otherwise it will be garbled. Http://www.phpcxz.com/a/web/phpweb/2011/0802/113.html