php search form with paged results proplem

Reply

Join Date: May 2008
Posts: 1
Reputation: bazwacky is an unknown quantity at this point 
Solved Threads: 0
bazwacky bazwacky is offline Offline
Newbie Poster

php search form with paged results proplem

 
0
  #1
May 20th, 2008
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['district'];
$type = @$_GET['type'];
$beds = @$_GET['beds'];
$condition = @$_GET['condition'];
$minprice = @$_GET['minprice'];
$maxprice = @$_GET['maxprice'];
$pool = @$_GET['pool'];


$records_per_page = 5;

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


// 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['Privatepools'] > 0 ) { echo "Private Pool"; } ; if ( $row['Communalpools'] > 0 ) { echo "Communal Pool"; } ; ?> </div>
<div id="result-general">
<?php if ($row['Fully Fitted Kitchen'] == 'yes') {echo "Fitted Kitchen";}; ?>
</div>

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




<?php }

if ($start >= $records_per_page)

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

}

{
echo "<a href=" . $_SERVER['PHP_SELF'] .
"?start=" . ($start+$records_per_page) . ">Next Page</a>";
}
}
?>
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 86
Reputation: sagedavis is an unknown quantity at this point 
Solved Threads: 6
sagedavis sagedavis is offline Offline
Junior Poster in Training

Re: php search form with paged results proplem

 
0
  #2
May 21st, 2008
You are using a lot of shorthand stuff, and it makes it hard for those of us who don't use it to read.
  1. (!$_GET['start']) ? $start = 0 : $start = $_GET['start'];
as an example.
so for those who don't get what that is
  1. if(!$_GET['start'])
  2. {
  3. $start = 0;
  4. }
  5. else
  6. {
  7. $start = $_GET['start'];
  8. }

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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the PHP Forum


Views: 753 | Replies: 1
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC