Đây là code phân trang bằng PHP hoàn chỉnh nhất, dưới đây là code liệt kê danh sách user có phân trang: PHP: <?phpmysql_connect("localhost","root","") or die ("Kết nối không thành công!");mysql_select_db("user") or die ("Không mở được DB!");mysql_query("set names utf8");echo "<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />";echo "<title>Liệt kê user</title>";$maxPages=2; // so link lien ket the hien$maxRows=3; // so hang du lieu tren 1 trang $query="select * from user"; // truy luc tat ca user$result = mysql_query($query) or die(mysql_error());$totalRows=mysql_num_rows($result); // lay tong so hang du lieu co trong bang csdl if(isset($_GET['page'])) $curPage=$_GET['page']; // lay thu tu trang hien taielse $curPage=1; //neu khong co so trang thi la trang dau tien$curRow=($curPage-1)*$maxRows; // tinh so hang du lieu bat dau $query="select * from user limit $curRow , $maxRows"; // lay $maxrow hang du lieu bat dau tu hang $curRow$result = mysql_query($query) or die(mysql_error());echo "<table border=1 width=500>";echo "<tr bgcolor=\"#00CCFF\"><td> ID </td><td> NICK </td><td> HỌ TÊN </td></tr>"; // hien thi du lieuwhile($row=mysql_fetch_array($result)){echo "<tr>";echo "<td>".$row['id']."</td>";echo "<td>".$row['nick']."</td>";echo "<td>".$row['ten']."</td>";echo "</tr>"; }echo "</table>";echo paging($totalRows,$curPage,$maxPages,$maxRows,"Phantrang.php"); // goi ham hien thi phan phan trang /*Ham thuc hien phan trang $totalRows: tong so hang du lieu trong bang csdl$curPg: trang du lieu hien tai$pg: so link lien ket the hien$re: so hang du lieu tren 1 trang$file: ten file chay phan trang*/function paging($totalRows,$curPg,$pg,$re,$file) { $paging=""; $mxR = $re; $mxP = $pg; if($totalRows%$mxR==0) $totalPages = (int)($totalRows/$mxR); else $totalPages = (int)($totalRows/$mxR+1); $curRow = ($curPg-1)*$mxR+1; if($totalRows>$mxR) { $start=1; $end=1; $paging1 =""; for($i=1;$i<=$totalPages;$i++) { if(($i>((int)(($curPg-1)/$mxP))* $mxP) && ($i<=((int)(($curPg-1)/$mxP+1))* $mxP)) { if($start==1) $start=$i; if($i==$curPg) $paging1 .= $i." "; else { $paging1 .= "<a class=lslink href=$file"; $paging1 .="?page=".$i.">".$i; $paging1 .="</a> "; } $end=$i; } } $paging.= "Trang : " ; if($curPg>$mxP) { $paging .="<a class=lslink href=$file"; $paging .="?page=".($start-1); $paging .=">Previous</a> "; } $paging.=$paging1; if(((int)(($curPg-1)/$mxP+1)*$mxP) < $totalPages) { $paging .= "<a class=lslink href=$file"; $paging .="?page=".($end+1); $paging .=">Next</a> "; } } return $paging; }?> đây là file Database: