Home >Backend Development >PHP Tutorial >php paging function_PHP tutorial
php paging function
php tutorial paging function
$conn=mysql tutorial_connect("localhost","root","123456");
$pagesize=4;//Set each page Number of records displayed on one page
mysql_select_db("ly",$conn);
$rs=mysql_query("select count(*) from lyb",$conn);//Get the total number of records $rs and calculate The total number of pages is calculated using
$myrow = mysql_fetch_array($rs);
$numrows=$myrow[0];
$pages=intval($numrows/$pagesize);//Calculate the total number of pages
if ($numrows%$pagesize)
$pages++;
//Set the number of pages
if (isset($_get['page'])){
$page=intval($ _get['page']);}
else{
//Set to the first page
$page=1;
}
//Calculate the record offset
$ offset=$pagesize*($page - 1);
//Read the specified number of records
$rs=mysql_query("select * from lyb order by id desc limit $offset,$pagesize",$conn) ;
if ($myrow = mysql_fetch_array($rs))
{
$i=0;
?>
";
do {
$i++;
?>
< ?=$myrow["nichen"]?>
}
while ($myrow = mysql_fetch_array($rs));
echo "
}