For beginners, what is the paging query function of PHP? if no query result is displayed, an error occurs? PHPcodeinclude (& quot; conn. php & quot;); functionpager ($ rows, $ page_size) {global $ page, $ select_from, $ select_limit, $ pagenav; $ page_countceil ($ rows $ p new paging problem, does the PHP paging generation query function cause an error if no query results exist?
PHP code
Include ("conn. php "); function pager ($ rows, $ page_size) {global $ page, $ select_from, $ select_limit, $ pagenav; $ page_count = ceil ($ rows/$ page_size ); if ($ page <= 1 | $ page = '') $ page = 1; if ($ page >=$ page_count) $ page = $ page_count; $ select_limit = $ page_size; $ select_from = ($ page-1) * $ page_size. ','; $ pre_page = ($ page = 1 )? 1: $ page-1; $ next_page = ($ page = $ page_count )? $ Page_count: $ page + 1; $ pagenav. = "$ page/$ page_count page $ rows records"; $ pagenav. = "homepage"; $ pagenav. = "previous page"; $ pagenav. = "next page"; $ pagenav. = "Last page"; $ pagenav. = "Jump\ N "; for ($ I = 1; $ I <= $ page_count; $ I ++) {if ($ I = $ page) $ pagenav. ="$ I\ N "; else $ pagenav. ="$ I\ N ";}} //// // calculate the record from $ select_from by using the pager function start retrieval, $ pagenav output paging navigation $ countsql = "select * from manager where 0 = 0 "; if ($ _ POST [chinaname]! = "") {$ Countsql = $ countsql. "and chinaname like '% $ _ POST [chinaname] %'";} if ($ _ POST [Tel]! = "") {$ Countsql = $ countsql. "and Tel like '% $ _ POST [Tel] %'";} $ rows = mysql_num_rows (mysql_query ($ countsql )); $ page = $ _ GET ['Page']; pager ($ rows, 2); $ SQL = "select * from manager where 0 = 0 "; if ($ _ POST [chinaname]! = "") {$ SQL = $ SQL. "and chinaname like '% $ _ POST [chinaname] %'";} if ($ _ POST [Tel]! = "") {$ SQL = $ SQL. "and Tel like '% $ _ POST [Tel] %'";} $ SQL = $ SQL. "limit $ select_from $ select_limit"; echo $ SQL; $ rst = mysql_query ($ SQL); while ($ row = mysql_fetch_array ($ rst )){The problem now is that when I have no results in fuzzy search, the statement displayed in limit is limit -.Should I solve this problem?------ Solution --------------------$ Page_count = ceil ($ rows/$ page_size );If no result is returned, $ rows is 0 and the resulting $ page_count is equal to 0.$ Select_from = (0-1) * 2 $ select_from returns-2.You can add a limit clause to judge that $ page_count is 0.