I have problem with page navigation.My problem is that am getting all the records in one page. $rowsPerPage = 10; I have 30 records, all are showed in one page...not the 10 records.Here is my code.
<?php
include ('conn.php');
// how many rows to show per page
$rowsPerPage = 10;
// by default we show first page
$pageNum = 1;
// if $_GET['page'] defined, use it as page number
if(isset($_GET['page']))
{
$pageNum = $_GET['page'];
}
// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;
$q = "show tables";
$r = mysql_query($q);
//$searchresult = array();
$var = $_POST['keyword'] ;
$trimmed = trim($var);
// rows to return
$limit=10;
// check for an empty string and display a message.
if ($trimmed == "")
{
echo "<p>Please enter a search...</p>";
exit;
}
// check for a search parameter
if (!isset($var))
{
echo "<p>We dont seem to have a search parameter!</p>";
exit;
}
while($data = mysql_fetch_array($r)) {
$table = $data[0]; // get the tablename
$query = "select * from ".$table." where dispname like '%".$trimmed."%'";
$result = mysql_query($query);
while($data = mysql_fetch_array($result)) {
// $searchresult[] = $rows['name'];
//$var =$rows['dispname'];
echo ' <tr> <td> <a href="'.$data['MedName'].'" >' . $data['dispname'].' </a> </td>';
echo'</tr>';
}
}
//$query = "SELECT val FROM randoms LIMIT $offset, $rowsPerPage";
//$result = mysql_query($query) or die('Error, query failed');
while(list($val) = mysql_fetch_array($result))
{
echo "$val <br>";
}
echo '<br>';
$query = "select * from ".$table." where dispname like '%".$trimmed."%'";
$result = mysql_query($query) or die('Error, query failed');
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];
$maxPage = ceil($numrows/$rowsPerPage);
$self = $_SERVER['PHP_SELF'];
if ($pageNum > 1)
{
$page = $pageNum - 1;
$prev = " <a href=\"$self?page=$page\">[Prev]</a> ";
$first = " <a href=\"$self?page=1\">[First Page]</a> ";
}
else
{
$prev = ' [Prev] '; // we're on page one, don't enable 'previous' link
$first = ' [First Page] '; // nor 'first page' link
}
if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$next = " <a href=\"$self?page=$page\">[Next]</a> ";
$last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> ";
}
else
{
$next = ' [Next] '; // we're on the last page, don't enable 'next' link
$last = ' [Last Page] '; // nor 'last page' link
}
echo $first . $prev . " Showing page <strong>$pageNum</strong> of <strong>$maxPage</strong> pages " . $next . $last;
?>