Novice paging related issues, PHP paging query function, no query results on the error

Source: Internet
Author: User
Novice paging problem, PHP paging generation query function, no query results on the error?
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 Total $rows records"; $pagenav. = "Home"; $pagenav. = "Previous page"; $pagenav. = "Next page"; $pagenav. = "Last"; $pagenav. = "Jump to\ n "; for ($i =1; $i <= $page _count; $i + +) {if ($i = = $page) $pagenav. = "$i\ n "; else $pagenav. = "$i\ n "; }}/////////////////////////////uses the pager function to calculate the $select _from from which record to start the retrieval, $pagenav output paging navigation $countsql = "SELECT * from manager WH  Ere 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 '];p ager ($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)) {Now the problem is that when I blur the query with no results, the statement shown here is limit-2,2Do you think this question should be solved at the moment?------Solution--------------------$page _count = ceil ($rows/$page _size);No results when the $rows is 0, the resulting $page_count is equal to 0, so the following$select _from = (0-1) * 2 $select _from got--2.You can add a judgment $page _count to 0 without the limit clause

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.