Home  >  Article  >  Backend Development  >  php5 mysql paging example code_PHP tutorial

php5 mysql paging example code_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:52:46762browse

Copy code The code is as follows:

//Connect to the database
$db=mysql_connect("localhost","root","");
mysql_select_db("hy",$db);
//Set the number of records displayed on each page
$pagesize=25;
//Get the total number of records and calculate the total number of pages
$res=mysql_query("select count(*) from main numrows/$pagesize);                                                                                                        page))
$page=1;
//Judge the number of pages to go to
if (isset($ys))
if ($ys>$pages)
$page=$ pages;
else
$page=$ys;
//Calculate the record offset > $res=mysql_query("select id,title from main order by id desc limit $offset,$pagesize" ,$db);
//Loop display of records
if ($myrow = mysql_f etch_array($res) )
{ $i=0;
?> >

Content

do $i++;                                                                   td> id=')" >

}
while ($myrow = mysql_fetch_array($res));
echo "" ;                                                                
//Display the total number of pages
echo "
There are ".$pages." pages (".$page."/".$pages.")Page ".$i ." " ";
echo ".$page."Page "; $i<=$pages;$i++)
echo "Page ".$i ." " ;

echo "
";
//Show the page number
echo "
";
//Calculate the page values ​​of the homepage, previous page, next page and last page                                                                                                      
$last=$pages;
if ($page>1)
{
echo "Home page                                                                    if ($page<$pages)
{
echo "Next page ";
echo "Last page " ";
}
echo "Go topage";
echo "";
echo "
";
echo "
";

?>






http://www.bkjia.com/PHPjc/318881.html

www.bkjia.com

true
http: //www.bkjia.com/PHPjc/318881.html

TechArticle

Statement:
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