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"];
}
?>

< _?php
$res = mysql_query("select *from test");
for ($i=0;$i< (mysql_num_rows($res)/$pagesize);$i++) {
if ($firstrec== $i*$pagesize)
echo "” . $i . ” | ” ;
else
echo “
$i | ” ;
}
?>
VN:F [1.1.6_502]
Rating: 0.0/5 (0 votes cast)
Share:
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • DotNetKicks
  • LinkedIn
  • Live
  • MySpace
  • StumbleUpon
  • Technorati

Related posts:

  1. Dynamic loading of content in a Dropdown box - without Ajax - Part II
  2. Dynamic loading of content in a Dropdown box - without Ajax - Part I
  3. MSSQL: Query to display objects in a database
  4. Single Page Editor #2 in PHP - Version 1.1
  5. Persist selections on Infragistics WebDataGrid paging

Leave a Reply

You must be logged in to post a comment.