For new users, the PHP paging generation query function causes an error if no query results exist.

Source: Internet
Author: User
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.

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.