Hi

I am quite new to php and mysql, i have built a property website and i am getting stuck with the paging of the results I can get the paging to work fine when i set the variables manually but when the variabes like type and price come from a search form only the 1st page of results works ? I assume this is something simple to sort out but its doing me head in cos ive been stuck on it for months.

The code is below can you please help or even send a link to a tutorial to explain the process

much appreciated

barry

<?php include("connections/connect.php"); ?>
<?php include("inc/top.php"); ?>
<div id="page-container">
<div id="results-main">


<?php


// get all varables from search form
$district = @$_GET;
$type = @$_GET;
$beds = @$_GET;
$condition = @$_GET;
$minprice = @$_GET;
$maxprice = @$_GET;
$pool = @$_GET;



$records_per_page = 5;


// look for starting marker
// if not availble assume 0
(!$_GET) ? $start = 0 : $start = $_GET;



// create query to count records


$query = "SELECT * FROM buysell WHERE type = '$type' ";
$result = mysql_query($query)
or die ( 'error in query' );


// get total number of records


$row = mysql_fetch_row($result);
$total_records = $row[0];


if (($total_records > 0) && ($start < $total_records))
{


// create query to get a batch of records
$query = "SELECT * FROM buysell WHERE type = '$type' LIMIT $start, $records_per_page";
$result = mysql_query($query)
or die ( ' error on paging ' );


while ($row = mysql_fetch_object($result))
{ ?>


<div id="page-container">
<div id="results-main">
<div id="result">
<div id="result-image">
<img src= <?php echo $row->Photo ?> width="180" height="125" border="0" ><img src="images/buttons/viewoff.png" />
</div>
<div id="result-type"> <?php echo $row->Type ?> </div>
<div id="result-price">£<?php echo $row->Price ?></div>
<div id="result-district"> <?php echo $row->District ?> ~ <?php echo $row->Location ?> </div>
<div id="result-general"> <?php echo $row->Bedrooms?> Beds   <?php if ( $row->Bedrooms < 1) { echo "studio"; } ;?>  </div>
<div id="result-district"> <?php if ( $row > 0 ) { echo "Private Pool"; } ; if ( $row > 0 ) { echo "Communal Pool"; } ;  ?> </div>
<div id="result-general">
<?php if ($row == 'yes') {echo "Fitted Kitchen";}; ?>
</div>


</div>
</div>
</div>



<?php }


if ($start >= $records_per_page)


{
echo "<a href=" . $_SERVER .
"?start=" . ($start-$records_per_page) . ">previous
page</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";


}


{
echo "<a href=" . $_SERVER .
"?start=" . ($start+$records_per_page) . ">Next Page</a>";
}
}
?>

Edited 3 Years Ago by happygeek: fixed formatting

You are using a lot of shorthand stuff, and it makes it hard for those of us who don't use it to read.

(!$_GET['start']) ? $start = 0 : $start = $_GET['start'];

as an example.
so for those who don't get what that is

if(!$_GET['start'])
{
 $start = 0; 
}
else
{
 $start = $_GET['start'];
}

now, on to the question, at hand.
I am not sure if this is the reason why your code is breaking or not, because this may be some other php shortcut that I am not aware of but, at the very end of your post, you have an if statement, however you do not have "else" between your two items.

as a side note... I personally prefer using ajax as a pagination method so that the whole query actually loads to the page, and when the user clicks to the next page, the transition doesn't make another query happen, it's almost instantanious.
Hope this helped.
Sage

This article has been dead for over six months. Start a new discussion instead.