Problem with code
| From: | Richard Kurth | Date: | Mon, 06 Dec 2004 05:05:12 +0000 |
| Subject: | Problem with code | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-203554@lists.php.net to get a copy of this message | ||
I am having a problem with the code below it provides the first page
with out any problem but when I select the next page it shows all the
results from the first page and the results from the second page. It
does the same thing on the third page also. I have been looking at it
for two days and can not fined the error in the code
<?php
include("include/common.php");
include("$config[template_path]/user_top.html");
// If current page number, use it
// if not, set one!
if(!isset($page)){
$page = 1;
} else {
$page = $page;
}
// Define the number of results per page
$max_results = $config['listings_per_page'];
// Figure out the limit for the query based
// on the current page number.
$from = (($page * $max_results) - $max_results);
//Process all the search results to create the sql
if($searchRule == "or"){ $cond = "OR"; } else $cond = "and";
//the main sql statment
$sql = 'SELECT * FROM listing ';
//the sql statment required to set the total number of pages
$sql1 = 'SELECT COUNT(*) as Num FROM listing ';
if($state != "" || $type != "" || $county != "" || $price !=
""){
$sql .= "WHERE ";
$sql1 .= "WHERE ";
if($state != ""){
$sql .= "state = '". $state ."'";
$sql1 .= "state = '". $state ."'";
if($state != "" || $type != "" || $county != "" || $price !=
""){
$sql .= " $cond ";
$sql1 .= " $cond ";
} }
if($type != ""){
$sql .= "type = '". $type ."'";
$sql1 .= "type = '". $type ."'";
if($state != "" || $type != "" || $county != "" || $price !=
"") {
$sql .= " $cond ";
$sql1 .= " $cond ";
} }
if($county != ""){
$sql .= "county = '". $county ."'";
$sql1 .= "county = '". $county ."'";
if($state != "" || $type != "" || $county != "" || $price !=
""){
$sql .= " $cond ";
$sql1 .= " $cond ";
} }
if($Pricerange != ""){
if($Pricerange=="range1"){
$Price1="00000";
$Price2="100000";
$simbale="<=";
$sql .= "price <= '". $Price2."'";
$sql1 .= "price <= '". $Price2."'";
}
if($Pricerange=="range2"){
$Price1="100000";
$Price2="150000";
$sql .= "(price > '". $Price1."' OR price <= '".
$Price2."')";
$sql1 .= "(price > '". $Price1."' OR price <= '".
$Price2."')";
}
if($Pricerange=="range3"){
$Price1="150000";
$Price2="200000";
$sql .= "(price > '". $Price1."' OR price <= '".
$Price2."')";
$sql1 .= "(price > '". $Price1."' OR price <= '".
$Price2."')";
}
if($Pricerange=="range4")
{$Price1="200000";
$Price2="250000";
$sql .= "(price > '". $Price1."' OR price <= '".
$Price2."')";
$sql1 .= "(price > '". $Price1."' OR price <= '".
$Price2."')";
}
if($Pricerange=="range5")
{$Price1="250000";
$Price2="300000";
$sql .= "(price > '". $Price1."' OR price <= '".
$Price2."')";
$sql1 .= "(price > '". $Price1."' OR price <= '".
$Price2."')";
}
if($Pricerange=="range6")
{$Price1="300000";
$Price2="";
$sql .= "price >= '". $Price1."'";
$sql1 .= "price >= '". $Price1."'";
}}
$sql .= " LIMIT " . $from . "," . $max_results;
}
$result=safe_query($sql);
while ($row = mysql_fetch_array($result)){
extract($row);
?>
<div align="center">
<table border="0" width="631" height="1"
cellpadding="0" cellspacing="0">
<tr>
<td width="81" height="1" bgcolor="#60A0F8"><font
color="#FFFFFF"><span class="contentsmall">Listing</span><span
class="contentbold">
#<? echo$listingId?></span></font><img hspace="0"
src="images/user_photos/thumb_5000_1.jpg" border="0" width="83"
height="50"><br>
</td>
<center>
<td width="401" height="1"><textarea cols="45"
rows="6"><? echo$descr1?></textarea> <br>
<a href="more_results.php?listingId=<?
echo$listingId?>&searchlistingid=yes">
more info...</a></td>
<td width="127" height="1"><span
class="contentbold">$<? echo$price?></span><br>
<?if ($type=="") {}?>
<?if ($type=="BUS") {echo 'Business Opportunities';}?>
<?if ($type=="COM") {echo 'Commercial';}?>
<?if ($type=="CON") {echo 'Condo/Townhouse';}?>
<?if ($type=="DUP") {echo 'Duplex';}?>
<?if ($type=="FAR") {echo 'Farms & Ranches';}?>
<?if ($type=="INC") {echo 'Income Properties';}?>
<?if ($type=="LAK") {echo 'Lake Properties/Waterfront';}?>
<?if ($type=="MOB") {echo 'Mobile Home';}?>
<?if ($type=="RES") {echo 'Residential';}?>
<?if ($type=="TIM") {echo 'Time Share';}?>
<?if ($type=="VAC") {echo 'Vacant Land';}?> <br>
<? echo$bedrooms?> BR / <? echo$bathrooms?> BA<br>
<? echo$city?>, <? echo$state?></td>
</tr>
</table>
<?}
$total_results = mysql_result(mysql_query($sql1),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=\"".$PHP_SELF."?page=$prev\"><<Previous</a> ";
}
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
echo "$i ";
} else {
echo "<a
href=\"".$PHP_SELF."?page=$i\">$i</a> ";
}
}
// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
echo "<a
href=\"".$PHP_SELF."?page=$next\">Next>></a>";
}
echo "</center>";
include("$config[template_path]/user_bottom.html");
?>
--
Best regards,
Richard mailto:rdkurth@directphp.com