this is the pagination code i am trying but it is just showing first page although i wrote prev and next code but nothing is displayed.
<?php
$state=trim( $_POST['txtstate']);
$property=trim( $_POST['txtpropertytype']);
$db_host = 'localhost';
$db_user = 'root';
$db_pass = '';
$db_database = 'begdb';
mysql_connect ($db_host, $db_user, $db_pass) or die ('Could not connect to the database.');
mysql_selectdb ($db_database) or die ('Could not select database.');
$limit = 5;
$query_count = "SELECT count(property_name) FROM propertymastb where (state = '" .$state. "') and (property_type = '" .$property. "')";
$result_count = mysql_query($query_count);
$totalrows = mysql_num_rows($result_count);
if(empty($page))
{
$page = 1;
echo $page;
}
$limitvalue = $page * $limit - ($limit);
$query = "SELECT property_name FROM propertymastb where (state = '" .$state. "') and (property_type = '" .$property. "')
LIMIT $limitvalue,$limit";
$result = mysql_query($query) or die("Error: " . mysql_error());
if(mysql_num_rows($result) == 0){
echo("Nothing to Display!");
}
$bgcolor = "#E0E0E0"; // light gray
/* Sets up one of the background colors. The color stated here will be
displayed second */
echo("<table>");
// Just a simple table
while($row = mysql_fetch_array($result))
{
/ This starts the loop (a while loop). What this does is returns a row of data
to the $row array. Each time the loop restarts, the next row of data is used.
So, each pass of the loop returns a different row of data. /
// Start The Background Check
if($bgcolor == "#E0E0E0"){
$bgcolor = "#FFFFFF";
}else{
$bgcolor = "#E0E0E0";
}
// Here we start table row & table data
// Make sure your bgcolor is the $bgcolor variable
echo($row["property_name"]);
/* Tip: This is how we add the users field from our row. You can use any field
from your row: all you do is include the field's name inbetween the array
brackets. Ex: $row["field_name_here"] */
// Here we end the one section of table data, and start another.
// Here we end the table data & table row
}
/ This closes the loop. Anything after this bracket will display after the
data you've pulled from the database. /
echo("</table>");
if($page != 1){
$pageprev = $page--;
// Fancy way of subtracting 1 from $page
echo("<a href='". "". $PHP_SELF ."?page=".$pageprev."'> prev </a>");
/* Tip: It is a good idea NOT to use $PHP_SELF in this link. It may work,
but to be 99.9% sure that it will, be sure to use the actual name of the file
this script will be running on. Also, the adds a space to the end of
PREV, and gives some room between the numbers. */
}else
echo("PREV".$limit." ");
$numofpages = $totalrows / $limit;
/* We divide our total amount of rows (for example 102) by the limit (25). This
will yield 4.08, which we can round down to 4. In the next few lines, we'll
create 4 pages, and then check to see if we have extra rows remaining for a 5th
page. */
for($i = 1; $i <= $numofpages; $i++)
{
/* This for loop will add 1 to $i at the end of each pass until $i is greater
than $numofpages (4.08). */
if($i == $page)
{
echo($i." ");
}else
{
echo("<a href='". "". $PHP_SELF ."?&page=".$i."'> $i </a>");
}
/* This if statement will not make the current page number available in
link form. It will, however, make all other pages available in link form. */
}
if(($totalrows % $limit) != 0){
/* The above statement is the key to knowing if there are remainders, and it's
all because of the %. In PHP, C++, and other languages, the % is known as a
Modulus. It returns the remainder after dividing two numbers. If there is no
remainder, it returns zero. In our example, it will return 0.8 */
if($i == $page){
echo($i." ");
}else{
echo(" <a href='". "". $PHP_SELF ."?&page=".$i."'> $i </a>");
}
/* This is the exact statement that turns pages into link form that is used
above */
}
if(($totalrows - ($limit * $page)) > 0)
{
/* This statement checks to see if there are more rows remaining, meaning there
are pages in front of the current one. */
$pagenext = $page++;
// Fancy way of adding 1 to page
echo("<a href='". "". $PHP_SELF ."?page=".$pagenext."'> NEXT </a>");
/* Since there are pages remaining, this outputs NEXT in link form. */
}
else
{
echo("NEXT".$limit);
/* If we're on the last page possible, NEXT will NOT be displayed in link
form. */
}
?>