<?PHP
$length = 10; // tedad radif dar safhe
$start = (int) $_REQUEST['page'] * $length; // shomare safhe * tedad dar safhe => shomare rcord e shoru`
$res=mysql_query(" SELECT * FROM `table_name` WHERE 1 ORDER BY `table_field` LIMIT $start,$length ");
/********table header start*******/
echo "<table><tr>";
$numfields=mysql_num_fields($res);
for($i=0; $i<$numfields; $i++){
$fieldRec = mysql_fetch_field($res);
$field_name[$i] = $fieldRec->name;
echo "<th>".$field_name[$i]."</th>";
}
echo "</tr>";
/********table header end*******/
/********table body start*******/
$num=mysql_num_rows($res);
for($i=0; $i<$num; $i++){
echo "<tr>";
$row = mysql_fetch_array($res);
for($j=0; $j<$numfields; $j++){
echo "<td>".$row[$field_name[$j]]."</td>";
}
echo "</tr>";
}
/********table body end*******/
echo "</table>";
/********links start*******/
$RecInTable=mysql_result(mysql_query(" SELECT * FROM COUNT(`table_field`) WHERE 1 "),0,0); // tedad record dar table, [[ rahe behtari hast? :-/ ]]
$pages=($RecInTable - $RecInTable%$length)/$length;
if($RecInTable%$length)$pages++;
for($k=0; $k<$pages; $k++){
if($k=intval($_REQUEST['page'])){
echo "<b>".($k+1)."</b>";
} else {
echo "<a href='?page=$k'>".($k+1)."</a> - ";
}
}
/********links end*******/
?>