Simple and practical php mysql paging code_PHP tutorial

WBOY
Release: 2016-07-13 17:05:10
Original
856 people have browsed it

Simple and practical php mysql paging code

Simple and practical php tutorial mysql tutorial paging code
$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 whether the offset parameter is passed to the script, if not, use the default value 0

if (empty($offset))
{
$offset=0;
}

//Query results (here are 20 items per page, but you can change it yourself)
$result=mysql_query("select id,name,phone from table where your_condition_here order by whatever limit $offset, 20");

//Display the 20 records returned
while ($data=mysql_fetch_array($result))
{

//Replace with the code you use to display the returned records

}

//Next step, write links to other pages
if(!$offset) //If the offset is 0, the link to the previous page will not be displayed
{
$preoffset=$offset-20;
print "Previous page n";
}

//Calculate the total number of pages required
$pages=ceil($nr/20); //$pages variable now contains the required number of pages

for ($i=1; $i <= $pages; $i++)
{
$newoffset=20*$i;
print "$i n";
}

//Check if it is the last page
if ($pages!=0 && ($newoffset/20)!=$pages)
{
print "Next page n";
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/630807.htmlTechArticleSimple and practical php mysql paging code simple and practical php tutorial mysql tutorial paging code $qh=mysql_query(select count(*) as rcnt from table where your_condition_here order by whatever); $dat...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template