// How Paging can be done in PHP
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Paging</title>
</head>
<body>
<?php
error_reporting("E_ALL ^ E_NOTICES");
define('MAX_REC_PER_PAGE', 28);
// find out how many rows are in the table
//$select = mysql_query("SELECT COUNT(*) FROM tablename where id='1' ") or die("Count query error!");
//list($total) = mysql_fetch_row($select);
$total = 65; // total number of item in database
$total_pages = ceil($total / 30); // in this we get total number of pages..set 30 item in per page..result 65/30 = 3 page
$page = intval(@$_GET["page"]); // intval() function is used to get the integer value of a variable.
if (0 == $page)
{
$page = 1; // if page is equal to 0 assign 1
}
$start = 30 * ($page - 1); // start page number
$max = 30; // number of items to show per page
?>
<table align="center">
<tr>
<td><font color="#000000">Page:</font></td>
<?php
for ($i = 1; $i <=$total_pages; $i++) // $i = 1 , total_page = 3
{
$txt = $i; // assign value
if ($page != $i)
$txt = "<a href=\"" . $_SERVER["PHP_SELF"] . "?page=$i\">$txt</a>"; //assign value to page...get from url
?>
<td align="center"><font color="#FF0000" > <?php echo $txt ?></font></td>
<?php
}
?>
</tr>
</table>
</body>
</html>
1 comment:
Paging show our query result in multiple pages instead of just put them all in one long page which makes our website look attractive....thanks sir...
Post a Comment