Code: Select all
andCode: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Can someone please help me solve this search form pagination thing. I am willing to pay now I am so desparate. This is one topic that no-one seems to know about. here is my code
There are examples of pagination everywhere on this site why is it so difficult
Here is the form from the html page
<form name ="search" id ="search" action = buying_2.php method=GET>
<p align="left" class="style24">Search >>> </p>
<p align="left">
<span class="style8"> Location:</span>
<select name=location value="<? if(isset($_GET['location'])) echo $_GET['location']; ?>" >
<option value=Canterbury>Canterbury
<option value=Whitstable>Whitstable
<option value=Herne Bay>Herne Bay
<option value=Faversham>Faversham
</select>
</p>
<p align="left"> <span class="style8">Price range:</span>
<select name=price_range value="<? if(isset($_GET['price_range'])) echo $_GET['price_range']; ?>" >
<option value=£100,000 to £200,000>£100,000 to £200,000
<option value=£200,000 to £300,000>£200,000 to £300,000
<option value=£300,000 to £400,000>£300,000 to £400,000
<option value=£400,000 to £500,000>£400,000 to £500,000
<option value=£500,000 to £600,000>£500,000 to £600,000
<option value=£600,000 to £700,000>£600,000 to £700,000
<option value=£700,000 to £800,000>£700,000 to £800,000
<option value=£800,000 to £900,000>£800,000 to £900,000
<option value=£900,000 to £1000,000>£900,000 to £1000,000
<option value=£1000,000 and Above>1000,000 and Above
</select>
</p>
<p align="left">
<span class="style8">Property type:</span>
<select name=property_type value="<? if(isset($_GET['property_type'])) echo $_GET['property_type']; ?>">
<option value=House>House
<option value=Flat>Flat
<option value=Rented>Rented
</select>
<input name="Submit" type = submit value = "Search" tabindex="3" >
</p>
<p align="left"> </p>
</span>
</form></td>
Here is the php page that collects user data from the form on the html page
?php
include("dbinfo_2.inc.php");
// Connect to contact database
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
// create variables to hold users input from form
$new_location = $_GET['location'];
$new_price_range = $_GET['price_range'];
$new_property_type = $_GET['property_type'];
if ($new_location=="")
{
$new_location='%';
}
if ($new_price_range=="")
{
$new_price_range='%';
}
if ($new_property_type=="")
{
$new_property_type='%';
}
// If current page number, use it
// if not, set one!
if(!isset($_GET['page'])){
$page = 1;
} else {
$page = $_GET['page'];
}
// Define the number of results per page
$max_results =4;
// Figure out the limit for the query based
// on the current page number.
$from = (($page * $max_results) - $max_results);
// Perform MySQL query on only the current page number's results
$result = mysql_query ("SELECT * FROM sellers_properties WHERE location LIKE '$new_location%' AND price_range LIKE '$new_price_range%' AND property_type LIKE '$new_property_type%' LIMIT $from, $max_results");
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM sellers_properties WHERE location LIKE '$new_location%' AND price_range LIKE '$new_price_range%' AND property_type LIKE '$new_property_type%'"),0);
?>
<?
if ($row=mysql_fetch_array($result)){
do{
?>
//here is all my formatted data to show results
<?
// Space between tables
//print("<p>");
}
while ($row = mysql_fetch_array($result));
}
// Let user know if no matching data found
//else {print "Sorry no records found";}
else print "<script>document.location.href='no_results.htm'</script>";
// Figure out the total number of results in DB:
//$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM sellers_properties WHERE location LIKE '$new_location%' AND price_range LIKE '$new_price_range%' AND property_type LIKE '$new_property_type%'"),0);
// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);
// Build Page Number Hyperlinks
echo "<center>Select a Page<br />";
// Build Previous Link
if($page > 1){
$prev = ($page - 1);
// echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\">Previous</a> ";
echo '<a href="'.$_SERVER['PHP_SELF'].'?page=' .$prev. '&new_location='.$_GET['location'].'&new_price_range='.$_GET['price_range'].'&new_property_type='.$_GET['property_type'].'">prev</a>';
//echo'<a href="buying_2.php?page='.$prev.'&new_location='.$_GET['location'].'&new_price_range='.$_GET['price_range'].'&new_property_type='.$_GET['property_type'].'">PREVIOUS</a> ';
}
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
echo "$i ";
} else {
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> ";
// echo '<a href="buying_2.php?page='.$i.$new_location, $new_price_range, $new_property_type.'">$i</a>';
}
}
// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
// echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">Next>></a>";
echo '<a href="'.$_SERVER['PHP_SELF'].'?page=' .$next. '&new_location='.$_GET['location'].'&new_price_range='.$_GET['price_range'].'&new_property_type='.$_GET['property_type'].'">next</a>';
//echo'<a href="buying_2.php?page='.$prev.'&new_location='.$_GET['location'].'&new_price_range='.$_GET['price_range'].'&new_property_type='.$_GET['property_type'].'">NEXT</a> ';
}
echo "</center>";
?>
Hope this helps
Your help is much appreciated
Simplecat
[color=red][b]Pimptastic[/b] | Please useCode: Select all
andCode: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]