Jump to content

PHP MySQL search form


hybmg57

Recommended Posts

I have below error when I try to parse a variable via GET request from a php search form to the php result page which is connected to MySQL.

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 0, 20' at line 10

 

Below is my code...I am getting this error when form name "City is parsed to this php page" funnily enough, when "MLS" is parsed, it works fine and retrieves correct listing...

 

Any ideas??

 

<?php
if (is_numeric($_GET['pg'])) {
        $pgnum = ((int) $_GET['pg']);
}

else {
        $pgnum = 0;
        $errorMessage = "Invalid value for page number";

}

$startnum = 1;
$nextpg = ($pgnum + 1);
$prevpg = ($pgnum-1);

if ($pgnum >= 0) {
        $offset = ($pgnum * 20);
}

else {
        $offset = 0;
}

$limit = 20; 
?>

<?php

$Property_Type=$_GET['property_type'];
$City=$_GET['city'];
$Beds=$_GET['beds'];
$Baths=$_GET['baths'];
$Lowest_Price=$_GET['lowest_price'];
$Highest_Price=$_GET['highest_price'];
$MLS=$_GET['mls_number'];


include("db.php");

$rets_login_url = "http://ntreisrets.mls.ntreis.net:80/rets/login";
$rets_username = "user";
$rets_password = "password";
$rets_agent = "agent";

require_once('phRets.php');

$rets = new phRets;

$connect = $rets->Connect($rets_login_url, $rets_username, $rets_password);
if (!$connect) {
        print_r($rets->Error());
}

?>
<body id="jrmolina-listing-detail" class="our-listings our-listings-landing" text>
<div id="page">
	<div id="content-container">
		<div id="content" class="clearfix">
			<div id="container">
				<div id="listings-container"> <div id="listings">

<?php

if($Highest_Price==0){
	$Any= ">=";
} else {
	$Any= "<=";
}

if($City==0){
	$Any_City= ">";
} else {
	$Any_City= "LIKE";
}
if($MLS==NULL){
	$Any_MLS= "IS NOT";
} else {
	$Any_MLS= "=";
}


$result = mysql_query("SELECT * 
				  FROM residential 
				  WHERE	PROPSUBTYPEDISPLAY LIKE '%{$Property_Type}%'
				  AND	AREA {$Any_City} '%{$City}%'
				  AND	BEDS >={$Beds}
				  AND	BATHSTOTAL >={$Baths}
				  AND	LISTPRICE >={$Lowest_Price}
				  AND	LISTPRICE {$Any} {$Highest_Price}
				  AND	MLSNUM {$Any_MLS} {$MLS}
				  LIMIT {$offset}, {$limit}")
or die(mysql_error());


?>
<div id="rha-mls-pager-container">

<?php


mysql_query("SELECT SQL_CALC_FOUND_ROWS * 
		FROM residential 
		WHERE	PROPSUBTYPEDISPLAY LIKE '%{$Property_Type}%'
		AND	AREA {$Any_City} '%{$City}%'
		AND	BEDS >={$Beds}
		AND	BATHSTOTAL >={$Baths}
		AND	LISTPRICE >={$Lowest_Price}
		AND	LISTPRICE {$Any} {$Highest_Price}
		AND	MLSNUM {$Any_MLS} {$MLS}
		LIMIT {$offset}, {$limit}");
$total_rows		=	mysql_query("SELECT FOUND_ROWS()");
$total_found	= 	mysql_fetch_array($total_rows);

$pages_count= $total_found[0] / $limit;
$num_pages=round($pages_count,0,PHP_ROUND_HALF_DOWN);

echo $total_found[0]." results found";
echo "<br/>";

if ($pgnum > 0) {
     echo("<a href='Search Results.php?op=Begin+Search&pg=" . $prevpg ."&property_Type=".urlencode($Property_Type)."&city=".$City."&beds=".$Beds."&baths=".$Baths."&lowest_price=".$Lowest_Price."&highest_price=".$Highest_Price. "'><< Previous
page</a>     ");
}  

if ($pgnum < $num_pages) {
     echo("<a href='Search Results.php?op=Begin+Search&pg=" . $nextpg . "&property_Type=".urlencode($Property_Type)."&city=".$City."&beds=".$Beds."&baths=".$Baths."&lowest_price=".$Lowest_Price."&highest_price=".$Highest_Price. "'>Next
page >></a>     ");
}  
echo "    ";
echo ($pgnum+1)." out of ".($num_pages+1);
?>
</div><!--/#rha-mls-pager-container-->
<br/>

<?php

while ($row = mysql_fetch_array($result)){
	echo	"<div class=\"vcard listing\">";
	echo	"<div class=\"information\">";
	echo "<span class=\"listprice\">\$".number_format($row['LISTPRICE'])."\n </span><br/>";
        echo "<p><span>{$row['STREETNUM']},{$row['STREETNAME']} ";
        echo "<BR/>{$row['CITY']}</span>";
        echo "{$row['STATE']}, {$row['ZIPCODE']}</p>";
	echo "<p><span>Beds: {$row['BEDS']}, Baths:{$row['BATHSTOTAL']}<br/>Square Feet: ".number_format($row['SQFTTOTAL'])." </span></p>";	
	echo	"</div>";

		$photos = $rets->GetObject("Property", "Thumbnail", "{$row['MLSNUM']}", "0", 1);
			foreach ($photos as $photo) {
					$listing = $photo['Content-ID'];
					$number = $photo['Object-ID'];

					if ($photo['Success'] == true) {
							echo "<img src='{$photo['Location']}\n' alt=\"\" title=\"\"  class=\"listing-photo photo\" width=\"146\" height=\"107\" />";
							echo "<a href=\"PropDetails.php?pg=" . $pgnum ."&property_Type=".$Property_Type."&city=".$City."&beds=".$Beds."&baths=".$Baths."&lowest_price=".$Lowest_Price."&highest_price=".$Highest_Price."&MLS=".$row['MLSNUM']."\" class=\"button url\">See Property Details</a>";
					}
					else {
							echo "<img src='images/no-image.png' alt=\"\" title=\"\"  class=\"listing-photo photo\" width=\"146\" height=\"107\" />";
							echo "<a href=\"PropDetails.php?MLS={$row['MLSNUM']}\" class=\"button url\">See Property Details</a>";
					}
			}


	echo "</div>";




}

?>

Link to comment
https://forums.phpfreaks.com/topic/205964-php-mysql-search-form/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.