Archive

Posts Tagged ‘limit’

How to Display records page by page ? or how to do pagination using php and my sql

March 15th, 2008 R Arun Raj No comments

<?php
include(‘includes/database.php’); //this is to execute the query

/**
* @author ["Arun Raj R , Software Engineer "]
* @copyright 2008
*/

if (isset($_REQUEST['page']))
{
$page = $_REQUEST['page'];
if($page==” || $page<1)
$page=1;
}
else
{
$page=1;
}
$start_from =($page-1) * 10;
$rs_result = QryExecute(“SELECT * FROM table_usp ORDER BY id DESC LIMIT $start_from,10″);
while ($row = mysql_fetch_assoc($rs_result)) {

echo $row['id'];
echo $row['name'];

}

?>

I think it may helpful to you . If you have any suggestions or questios pls reply here

or u can use this code

<?php
include(‘includes/database.php’);
$page = 0;
if(isset($_REQUEST['page']))
{
  if(intval($_REQUEST['page'])==$_REQUEST['page'])
  {
    $page = $_REQUEST['page'];
  }
}
define(‘RESULTS’,10);

$start = $page*RESULTS;
$sql = ‘SELECT * FROM table_up ORDER BY id DESC LIMIT ‘.$start.’,’.RESULTS;
$rs = QryExecute($sql);
while($obj = mysql_fetch_object($rs))
{
echo ‘<pre>’;
print_r($obj);
echo ‘</pre>’;
}
?>

Categories: Misk Tags: , , ,