Simple Paging feature with PHP and MySQL
This is not a full-featured code, but you can develop it to one.
Simple Paging feature with PHP and MySQL
< _?php
$db = mysql_connect("localhost","root");
mysql_select_db("test");
$pagesize = 2;
$res = mysql_query("select *from test");
$totalrecs = mysql_num_rows($res);
if (!isset($firstrec)) $firstrec = 0;
if (isset($_REQUEST['action'])) {
$firstrec = $_REQUEST['firstrec'];
switch ($_REQUEST['action']) {
case "prev":
if ($firstrec > 0)
$firstrec-= $pagesize ;
break;
case “next”:
if ($firstrec < $totalrecs-$pagesize )
$firstrec+=$pagesize;
break;
}
}
$res = mysql_query("select *from test limit " . $firstrec . ", " . $pagesize);
while ($row = mysql_fetch_assoc($res)) {
echo "
” . $row["id"] . ” ” . $row["name"];
}
?>























Leave a Reply
You must be logged in to post a comment.