Copy CodeThe code is as follows:
Connecting to a database
$db =mysql_connect ("localhost", "root", "");
mysql_select_db ("Hy", $db);
Set the number of records to display per page
$pagesize = 25;
Get the total number of records, calculate the total pages used
$res =mysql_query ("SELECT count (*) from main", $db);
$myrow = Mysql_fetch_array ($res);
$numrows = $myrow [0];
Calculate Total Pages
$pages =intval ($numrows/$pagesize);
if ($numrows% $pagesize)
$pages + +;
Determine whether pages are set or not, as defined as the home page
if (!isset ($page))
$page = 1;
Determine the number of pages to go
if (Isset ($ys))
if ($ys > $pages)
$page = $pages;
Else
$page = $ys;
Calculate record offset
$offset = $pagesize * ($page-1);
Fetch Records
$res =mysql_query ("Select Id,title from main order by id desc limit $offset, $pagesize", $db);
Cyclic display of records
if ($myrow = mysql_fetch_array ($res))
{
$i = 0;
?>
|
Content |
do {$i + +; ?>
|
') ' > |
} while ($myrow = Mysql_fetch_array ($res)); echo "
" ;
}
Show Total Pages
echo "Shared". $pages. " Page (". $page." /". $pages.")
";
Show number of pages
for ($i =1; $i < $page; $i + +)
echo "First". $i. " Page ";
echo "First". $page. " Page ";
for ($i = $page +1; $i <= $pages; $i + +)
echo "First". $i. " Page ";
echo "
";
Show go to Page
echo "";
echo "";
?>
http://www.bkjia.com/PHPjc/318881.html www.bkjia.com true http://www.bkjia.com/PHPjc/318881.html techarticle Copy the code as follows:? PHP//Connection Database $db =mysql_connect ("localhost", "root", "" "), mysql_select_db (" Hy ", $db);//Set the number of records displayed per page $ pagesize=25; Get Records ...