mysql| page | Show recently, there are people in the forum who are asking how to implement the paging display of query results. I hope the following code will help you improve your program. The code is for MySQL, but it's easy to migrate to other SQL.
Because of the specificity of each program, I used some very common statements in the MySQL query. Replace the table with your form name, replace Your_condition_here with your conditional statement, and replace whatever with the field name you want to sort by (and, of course, if you want to order the reverse, don't forget to add the DESC clause).
<?php
$qh=mysql_query ("Select COUNT (*) as rcnt from TABLE WHERE your_condition_here order by WHATEVER");
$data=mysql_fetch_array ($QH);
$nr=$data["rcnt"];
Determine if the offset parameter is passed to the script, and if not, use the default value 0
if (empty ($offset))
{
$offset=0;
}
Query results (Here are 20 per page, but you can completely change it)
$result=mysql_query ("Select Id,name,phone from TABLE WHERE your_condition_here order by WHATEVER LIMIT $offset, 20");
Show 20 Records returned
while ($data=mysql_fetch_array ($result))
{
For the code you used to display the return record.
}
Next, write a link to another page
if (!$offset)//If the offset is 0, the link to the previous page is not displayed
Print "<a href=" $php_self?offset=$newoffset "> next page </a> \ n";
}
?>
This is just to give you a general introduction to the implementation of the Query results page display method, the other features you do yourself.
Note two: $php_self only an offset parameter, you can add your own things as needed; This approach is inefficient for queries that contain tables above millions records.
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.