| | |
php search form with paged results proplem
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: May 2008
Posts: 1
Reputation:
Solved Threads: 0
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> ";
}
{
echo "<a href=" . $_SERVER['PHP_SELF'] .
"?start=" . ($start+$records_per_page) . ">Next Page</a>";
}
}
?>
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> ";
}
{
echo "<a href=" . $_SERVER['PHP_SELF'] .
"?start=" . ($start+$records_per_page) . ">Next Page</a>";
}
}
?>
•
•
Join Date: Nov 2007
Posts: 86
Reputation:
Solved Threads: 6
You are using a lot of shorthand stuff, and it makes it hard for those of us who don't use it to read.
as an example.
so for those who don't get what that is
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
PHP Syntax (Toggle Plain Text)
(!$_GET['start']) ? $start = 0 : $start = $_GET['start'];
so for those who don't get what that is
PHP Syntax (Toggle Plain Text)
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
![]() |
Other Threads in the PHP Forum
- Previous Thread: PHP not displaying all content.
- Next Thread: Little code confusion
| Thread Tools | Search this Thread |
advanced apache api array beginner binary broken cakephp check checkbox class cms code cookies cron curl database date datepart display dropdownlist dynamic echo email eregi error execution file files folder form forms function functions google head href htaccess html if...loop image include includingmysecondfileinthechain insert ip javascript job joomla jquery key library limit link login mail menu mlm multiple mysql oop password paypal pdf pdfdownload php phpvotingscript problem query radio random recursion remote screen script search server sessions smarty sms sorting source space sql startup stored syntax system table traffic tutorial unicode update upload url validator variable video web youtube zend





