Bạn dùng thử đoạn code phân trang này xem nhé.
Code:
<?php
//tim tong so tra lai
function number($table,$catid)
{
$select="select * from $table where `catid`='$catid' order by location ASC";
$result=mysql_query($select) or die("can't not truy van number");
$n_record=mysql_num_rows($result);//so ban ghi cua bang
return $n_record;
}
//so trang
function num_page($p,$n_record)
{
if($n_record%$p==0)
{
$n_page=$n_record/$p;
return $n_page;
}
else
{
$n_page=($n_record-($n_record%$p))/$p+1;
return $n_page;
}
}
//hien so trang
function view_page($page_number,$n_record,$links,$p)
{
$vonglap=num_page($p,$n_record);
echo "<DIV align='right'>";
echo "Trang:";
for($i=1;$i<=$vonglap;$i++)
{
if ($page_number == $i){
echo "<a href='$links&page=".$i."'> [".$i."]</a>";
}else{
echo "<a href='$links&page=".$i."'> ".$i."</a>";
}
}
}
?>