Pagination of PHP search results

Source: Internet
Author: User
PHP search results are displayed on the page. the problematic homepage is displayed. no data is displayed on pages... Code
Include_once ("script/conn. php "); class Page {private $ curPage; // The current Page private $ totalPages; // The total number of data pages displayed private $ dispNum; // The number of data entries displayed on each page is private $ queryStr; // The queried SQL statement is private $ limitStr; // The limit control statement after the query statement is private $ currentPage; // Obtain the public function _ construct ($ queryStr = '', $ dispNum = 3) {$ result = mysql_query ($ queryStr ); $ totalNum = mysql_num_rows ($ result); $ this-> dispNum = $ dispNum; $ currentPage = basename ($ _ SERVER ["PHP_SELF"]); // part of the file name in the returned path $ this-> totalPages = ceil ($ totalNum/$ dispNum ); $ this-> queryStr = $ queryStr; $ temp = (isset ($ _ GET ["curPage"])? $ _ GET ["curPage"]: 1); $ this-> setCurPage ($ temp); $ this-> showCurPage (); $ this-> showFoot ();} private function showCurPage () {$ this-> limitStr = 'limit '. ($ this-> curPage-1) * $ this-> dispNum ). ','. $ this-> dispNum; $ result = mysql_query ($ this-> queryStr. $ this-> limitStr); while ($ row = mysql_fetch_assoc ($ result) {echo ""; echo"
";}} Private function setCurPage ($ curPage) {if ($ curPage <1) {$ curPage = 1;} else if ($ curPage >$ this-> totalPages) {$ curPage = $ this-> totalPages;} $ this-> curPage = $ curPage;} private function showFoot () {echo 'homepage done'; echo 'curpage-1 ). '"> Previous Page'; echo 'curpage + 1 ). '"> Next Page comment'; echo 'totalpages. '"> Last Page comment'; echo" total ". $ this-> totalPages. "page marker"; echo "current number ". $ this-> curPage. "page" ;}}$ keyword =$ _ POST ['search']; $ sq L = mysql_query ("select * from didian where name like '% $ keyword %'"); $ raw = @ mysql_fetch_object ($ SQL); if (! $ Raw) {echo "the information you searched for does not exist. please search with similar keywords! ";}
If this output is used independently, it is okay .. However, if this line is added, no data is displayed on the page. this is the condition for determining the search box.
Switch ($ keyword) {case 'guilin ': $ pages = new Page ('select * FROM 'image _ GUILIN'', 3); break; case 'Hainan ': $ pages = new Page ('select * FROM 'image _ hainance', 3); break; case 'Beijing ': $ pages = new Page ('select * FROM 'image _ beijing '', 3); break; case 'jiuzhaigou ': $ pages = new Page ('select * FROM 'image _ jiuzhaigou '', 3); break; case 'taihang mountain ': $ pages = new Page ('select * FROM 'image _ taihengshance', 3); break; case 'Shangri-La ': $ pages = new Page ('select * FROM 'image _ xianggelila ', 3); break; case 'xiaoxinggan ': $ pages = new Page ('select * FROM 'image _ xiaoxinganling', 3); break; case 'xishuangbanna ': $ pages = new Page ('select * FROM 'image _ xishuangbannaca', 3); break ;}

Next is the html search box jump

I don't know why .. Ask for advice...


Reply to discussion (solution)

You did not include the keyword parameter when turning pages.

Private function showFoot (){
Echo 'homepage done ';
Echo 'curpage-1). '"> Previous Page success ';
Echo 'curpage + 1). '"> Next Page comment ';
Echo 'totalpages. '"> last pagination ';
Echo "total". $ this-> totalPages. "page details ";
Echo "current". $ this-> curPage. "page ";
}

The keyword parameter must be added here.
Echo 'curpage-1). '"> Previous Page success ';

You did not include the keyword parameter when turning pages.

Private function showFoot (){
Echo 'homepage done ';
Echo 'curpage-1). '"> Previous Page success ';
Echo 'curpage + 1). '"> Next Page comment ';
Echo 'totalpages. '"> last pagination ';
Echo "total". $ this-> totalPages. "page details ";
Echo "current". $ this-> curPage. "page ";
}

The keyword parameter must be added here.
Echo 'curpage-1). '"> Previous Page success ';

Still no data
What if there are no parameters on the homepage? This is the homepage's http: // localhost: 808/Web/search. php
This is the second page of http: // localhost: 808/Web/search. php? CurPage = & curPage = 2
Do I have to add anything to the form action? I changed it according to yours.
Private function showFoot () {echo 'homepage failed'; echo 'curpage-1 ). '"> Previous Page'; echo 'curpage + 1 ). '"> Next Page comment'; echo 'totalpages. '"> Last Page comment'; echo" total ". $ this-> totalPages. "page marker"; echo "current number ". $ this-> curPage. "page ";}

$ Keyword is not passed in showFoot, of course not.

$ Keyword is not passed in showFoot, of course not.


So how can we change it? I don't know where to change it ..

At least.
Echo'

Rivate function showFoot () {echo 'homepage failed'; echo 'curpage-1 ). '"> Previous Page'; echo 'curpage + 1 ). '"> Next Page comment'; echo 'totalpages. '"> Last Page comment'; echo" total ". $ this-> totalPages. "page marker"; echo "current number ". $ this-> curPage. "page ";}


You cannot get $ keyword in this method, so it is null.
Add a parameter.
 DispNum = $ dispNum; $ this-> keyword = $ keyword; $ currentPage = basename ($ _ SERVER ["PHP_SELF"]); // return the file name section in the path $ this-> totalPages = ceil ($ totalNum/$ dispNum); $ this-> queryStr = $ queryStr; $ temp = (isset ($ _ GET ["curPage"])? $ _ GET ["curPage"]: 1); $ this-> setCurPage ($ temp); $ this-> showCurPage (); $ this-> showFoot ();} private function showCurPage () {$ this-> limitStr = 'limit '. ($ this-> curPage-1) * $ this-> dispNum ). ','. $ this-> dispNum; $ result = mysql_query ($ this-> queryStr. $ this-> limitStr); while ($ row = mysql_fetch_assoc ($ result) {echo ""; echo"
";}} Private function setCurPage ($ curPage) {if ($ curPage <1) {$ curPage = 1;} else if ($ curPage >$ this-> totalPages) {$ curPage = $ this-> totalPages;} $ this-> curPage = $ curPage;} private function showFoot () {echo 'keyword. '& curPage = 1 "> homepage comment'; echo 'keyword. '& curPage = '. ($ this-> curPage-1 ). '"> Previous Page'; echo 'keyword. '& curPage = '. ($ this-> curPage + 1 ). '"> Next Page comment'; echo 'keyword. '& curPage = '. $ this-> totalPages.' "> Last Page comment '; echo" total ". $ this-> totalPages. "page marker"; echo "current number ". $ this-> curPage. "page" ;}}$ keyword =$ _ POST ['search']; $ SQL = mysql_query ("select * from didian where name like '% $ keyword % '"); $ raw = @ mysql_fetch_object ($ SQL); if (! $ Raw) {echo "the information you searched for does not exist. please search with similar keywords! ";}?>

Parameters must be added during the call.
$ Pages = new Page ('select * FROM 'image _ GUILIN' ', $ keyword, 3 );

Parameters must be added during the call.
$ Pages = new Page ('select * FROM 'image _ GUILIN' ', $ keyword, 3 );


Or not .. The homepage I searched out has no suffix parameter http: // localhost: 808/Web/search. php.

At least.
Echo'
The homepage has no parameters .. Only the next page address has parameters ..

$ Keyword = $ _ POST ['search'];
1. the name of the parameter you obtained is search, not keyword.
2. because the page is using get, it cannot be obtained.

Change it to this.

 DispNum = $ dispNum; $ this-> keyword = $ keyword; $ currentPage = basename ($ _ SERVER ["PHP_SELF"]); // return the file name section in the path $ this-> totalPages = ceil ($ totalNum/$ dispNum); $ this-> queryStr = $ queryStr; $ temp = (isset ($ _ GET ["curPage"])? $ _ GET ["curPage"]: 1); $ this-> setCurPage ($ temp); $ this-> showCurPage (); $ this-> showFoot ();} private function showCurPage () {$ this-> limitStr = 'limit '. ($ this-> curPage-1) * $ this-> dispNum ). ','. $ this-> dispNum; $ result = mysql_query ($ this-> queryStr. $ this-> limitStr); while ($ row = mysql_fetch_assoc ($ result) {echo ""; echo"
";}} Private function setCurPage ($ curPage) {if ($ curPage <1) {$ curPage = 1;} else if ($ curPage >$ this-> totalPages) {$ curPage = $ this-> totalPages;} $ this-> curPage = $ curPage;} private function showFoot () {echo 'keyword. '& curPage = 1 "> homepage comment'; echo 'keyword. '& curPage = '. ($ this-> curPage-1 ). '"> Previous Page'; echo 'keyword. '& curPage = '. ($ this-> curPage + 1 ). '"> Next Page comment'; echo 'keyword. '& curPage = '. $ this-> totalPages.' "> Last Page comment '; echo" total ". $ this-> totalPages. "page marker"; echo "current number ". $ this-> curPage. "page" ;}}$ keyword =$ _ REQUEST ['search']; $ SQL = mysql_query ("select * from didian where name like '% $ keyword % '"); $ raw = @ mysql_fetch_object ($ SQL); if (! $ Raw) {echo "the information you searched for does not exist. please search with similar keywords! ";}?>

$ Keyword = $ _ POST ['search'];
1. the name of the parameter you obtained is search, not keyword.
2. because the page is using get, it cannot be obtained.

Change it to this.

 DispNum = $ dispNum; $ this-> keyword = $ keyword; $ currentPage = basename ($ _ SERVER ["PHP_SELF"]); // return the file name section in the path $ this-> totalPages = ceil ($ totalNum/$ dispNum); $ this-> queryStr = $ queryStr; $ temp = (isset ($ _ GET ["curPage"])? $ _ GET ["curPage"]: 1); $ this-> setCurPage ($ temp); $ this-> showCurPage (); $ this-> showFoot ();} private function showCurPage () {$ this-> limitStr = 'limit '. ($ this-> curPage-1) * $ this-> dispNum ). ','. $ this-> dispNum; $ result = mysql_query ($ this-> queryStr. $ this-> limitStr); while ($ row = mysql_fetch_assoc ($ result) {echo ""; echo"
";}} Private function setCurPage ($ curPage) {if ($ curPage <1) {$ curPage = 1;} else if ($ curPage >$ this-> totalPages) {$ curPage = $ this-> totalPages;} $ this-> curPage = $ curPage;} private function showFoot () {echo 'keyword. '& curPage = 1 "> homepage comment'; echo 'keyword. '& curPage = '. ($ this-> curPage-1 ). '"> Previous Page'; echo 'keyword. '& curPage = '. ($ this-> curPage + 1 ). '"> Next Page comment'; echo 'keyword. '& curPage = '. $ this-> totalPages.' "> Last Page comment '; echo" total ". $ this-> totalPages. "page marker"; echo "current number ". $ this-> curPage. "page" ;}}$ keyword =$ _ REQUEST ['search']; $ SQL = mysql_query ("select * from didian where name like '% $ keyword % '"); $ raw = @ mysql_fetch_object ($ SQL); if (! $ Raw) {echo "the information you searched for does not exist. please search with similar keywords! ";}?>


Well, I am so grateful !!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.