943,670 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1571
  • PHP RSS
May 20th, 2008
0

php search form with paged results proplem

Expand Post »
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>";
}
}
?>
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bazwacky is offline Offline
1 posts
since May 2008
May 21st, 2008
0

Re: php search form with paged results proplem

You are using a lot of shorthand stuff, and it makes it hard for those of us who don't use it to read.
PHP Syntax (Toggle Plain Text)
  1. (!$_GET['start']) ? $start = 0 : $start = $_GET['start'];
as an example.
so for those who don't get what that is
PHP Syntax (Toggle Plain Text)
  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
Reputation Points: 10
Solved Threads: 6
Junior Poster in Training
sagedavis is offline Offline
86 posts
since Nov 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: PHP not displaying all content.
Next Thread in PHP Forum Timeline: Little code confusion





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC