A little better. I am querying database and receiving results to display over 2 pages which is correct. But when i click the 2nd page or next it displays another 6 pages which is all the results in the database. Then if i click previous all the item before the field i was searching for appears before it pushing the required search fields down the ladder. I have pasted the exact code i am using below. Please tell me if i am doing anything wrong. I have also placed brackets around $keyword value after the regexp as i received a mysql error if i didnt.
Thanks
<html><head>
</head>
<body>
<?
$page = $_GET['page'];
$search_value=$HTTP_POST_VARS['search_value'];
global $search_value,$result, $page;
$search_value = addslashes($search_value);
// include connections strings here
@ $db= mysql_pconnect('localhost', 'username', 'password');
if (!$db)
{
echo 'Error: Could not connect to database. Please try again later.';
exit;
}
mysql_select_db('dbname');
$limit = 4;
$query_count = "SELECT * FROM properties WHERE value REGEXP '($search_value)' order by value desc ";
$result_count = mysql_query($query_count);
$totalrows = mysql_num_rows($result_count);
if(empty($page)){
$page = 1;
}
$limitvalue = $page * $limit - ($limit);
$query = "SELECT * FROM properties WHERE value REGEXP '($search_value)' LIMIT $limitvalue, $limit";
$result = mysql_query($query);
$num=mysql_num_rows($result);
if(mysql_num_rows($result) == 0){
echo("Nothing to Display!");
}
$i = 0;
echo "Listing of items in our database<br><p>";
while ($i < $num):
$id=mysql_result($result,$i,"id");
$region=mysql_result($result,$i,"region");
$value=mysql_result($result,$i,"value");
echo "$region <br>";
echo "$value <br> ";
echo "<a href=\"view_item.php?id=$id\">View</a> <br>";
$i++;
endwhile;
if($page != 1){
$pageprev = $page-1;
echo("<a href=\"$PHP_SELF?page=$pageprev&$search_value=sear ch\">PREV ".$limit."</a> ");
}else{
echo("PREV " .$limit." ");
}
$numofpages = $totalrows / $limit;
for($i = 1; $i <= $numofpages; $i++){
if($i == $page){
echo($i." ");
}else{
echo("<a href=\"$PHP_SELF?page=$i&search=$search_value\">$i </a> ");
}
}
if(($totalrows % $limit) != 0){
if($i == $page){
echo($i." ");
}else{
echo("<a href=\"$PHP_SELF?page=$i&search=$search_value\">$i </a> ");
}
}
if(($totalrows - ($limit * $page)) >=0){
$pagenext = $page+1;
echo(" <a href=\"$PHP_SELF?page=$pagenext&search=$search_val ue\">NEXT ".$limit."</a>");
}else{
echo(" NEXT " .$limit);
}
mysql_free_result($result);
?>
</center>
</body>
</html>