You are on page 1of 1

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Phan trang trong PHP</title>
<style>
body{margin: 20 100; font:normal 24pt Arial;color:navy;line-height:180%}
</style>
</head>
<body>
Tng s records ca table: 67<br>
Tng s records trn mt trang: 20 <br><hr>
<?php
$url="test.php";
$records=67; // tng s records ca table
$limit=20;
// s record trn mt trang
$pages=(($records % $limit)==0?(int)($records/$limit):(int)($records/$limit)+1);
// tng s trang phi trnh by.
/* --------- ly trang cn hin th, 1->pages ---------- */
if(isset($_GET["page"]))
$cur=$_GET["page"]+0;
else $cur=1;
/* --------- hin th trang $cur ----------------------- */
$start=($cur-1)*$limit;
$sql="Select * from GIDO limit <font color=red>$start</font>,$limit";
echo $sql."<br>";
/*---------- to lin kt n cc trang --------------- */
$str="";
for($i=1;$i<=$pages;$i++){
$str.="<a href=$url?page=$i>$i</a>".($i<$pages?"&nbsp;| &nbsp;":"");
/* phi b dng trn
if($i==$cur) $str.="<a href=$url?page=$i><font color=red>$i</font></a>".
($i<$pages?"&nbsp;| &nbsp;":"");
else $str.="<a href=$url?page=$i>$i</a>".($i<$pages?"&nbsp;| &nbsp;":"");
*/
}
/* ----------------------- iu khin NEXT, PREV -------------- */
/*
if($cur>1) {
$j=$cur-1;$prev="<a href=$url?page=$j>Prev</a> &nbsp; | &nbsp;";
$str=$prev.$str; }
if($cur<$pages) {
$j=$cur+1;$next="&nbsp; | &nbsp;<a href=$url?page=$j>Next</a>";
$str=$str.$next; }
*/
echo $str;
?>
</body>
</html>

You might also like