Jump to content

search


marquis

Recommended Posts

ok here is my code

<html><head><link rel="stylesheet" href="CSS.css" type="text/css" /><title>Search Results</title></head><body><div id="sidebar"><img src="images/bigdoglogo.gif" width="215"height="75"><div id="menu"><a href="Home.html">Home</a><a href="Apartments.php">Apartments</a><a href="Industrial.php">Industrial</a><a href="Land.php">Land</a><a href="Retail.php">Retail</a><a href="OfficeSpace.php">Office Space</a><a href="AboutUs.html">About Us</a><a href="CMS.php">Realtor login</a></div></div><div id="content"></body><?phpif($_GET["city"])$city=$_GET["city"];else$city='%';if($_GET["state"])$state=$_GET["state"];else$state='%';if($_GET["zipcode"])$zipcode=$_GET["zipcode"];else$zipcode='%';if($_GET["pricemin"])$pricemin=$_GET["pricemin"];if($_GET["pricemax"])$pricemax=$_GET["pricemax"];else$pricemax='%';if($_GET["bathsmin"])$bathsmin=$_GET["bathsmin"];if($_GET["bathsmax"])$bathsmax=$_GET["bathsmax"];else$bathsmax='%';if($_GET["bedroomsmin"])$bedroomsmin=$_GET["bedroomsmin"];if($_GET["bedroomsmax"])$bedroomsmax=$_GET["bedroomsmax"];else$bedroomsmax='%';if($_GET["county"])$county=$_GET["county"];else$county='%';if($_GET["buyorlease"])$buyorlease=$_GET["buyorlease"];else$buyorlease='%';$con = mysql_connect("localhost","root","*****");if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("realestate", $con);$result = mysql_query("SELECT * FROM estateWHERE city='".$city."'AND state='".$state."'AND zipcode='".$zipcode."'AND priceBETWEEN '".$pricemin."' AND '".$pricemax."'AND bathsBETWEEN '".$bathsmin."' AND '".$bathsmax."'AND bedroomsBETWEEN '".$bedroomsmin."' AND '".$bedroomsmax."'AND county='".$county."'AND buyorlease='".$buyorlease."'");while($row = mysql_fetch_array($result)) {echo "<table border='1'> <tr> <th>Address</th> <th>Price</th> <th>Baths</th> <th>Bedrooms</th> <th>State</th> <th>City</th> <th>Square Feet</th> <th>County</th> <th>Year Built</th> <th>Buy or Lease</th> </tr>";  echo "<tr>"; echo "<td>" . $row['address'] . "</td>"; echo "<td>" . $row['price'] . "</td>"; echo "<td>" . $row['baths'] . "</td>"; echo "<td>" . $row['bedrooms'] . "</td>"; echo "<td>" . $row['state'] . "</td>"; echo "<td>" . $row['city'] . "</td>"; echo "<td>" . $row['squarefeet'] . "</td>"; echo "<td>" . $row['county'] . "</td>"; echo "<td>" . $row['yearbuilt'] . "</td>"; echo "<td>" . $row['buyorlease'] . "</td>"; echo "</tr>"; echo "</table>";  }if($result==0)ECHO "<h3>NO MATCHES FOUND!</h3>";mysql_close($con);?></body></html>

as far as error go its working but i am having 2 problemif no search results far found i want it to say none are foundalso i am trying to make it to where if nothing is entered in the form i want it to disregard that part of the form i tried to do this by using wildcards but this didn't work

Link to comment
Share on other sites

Im trying to answer the second question. since you are already using IF statements to check empty strings, you can use the same for building the SQL Query rather than using wildcard... something like this$SQL = "SELECT * FROM estate WHERE";if($_GET["city"]) {$city=$_GET["city"];$SQL = $SQL . 'city='".$city."'' . 'AND';}if($_GET["state"]) {$state=$_GET["state"];$SQL = $SQL . 'state='".$state."'';}.......................'So in every IF statement build the SQL query..$result = mysql_query($SQL);..........

Link to comment
Share on other sites

while this is a good idea i had already though of that and while this get me around the empty strings part of it it doesnt help me with the fact that im going to need a wild card are something to that effect to set the max price as if they dont want there to be a max max price.with the min price i can achieve the same thing by setting the min price to zero. I say max price but the applies to all the max values in the form.

Link to comment
Share on other sites

Incase of min and max values there are 4 options, you can identify these with if statements...1. missing both min and max - nothing to add to the $SQL, no price constrain.2. contains max / missing min - $SQL .= 'price<='".$pricemax."''3. contains min / missing max - $SQL .= 'price>='".$pricemin."''4. contains both min and max - use BETWEEN '".$pricemin."' AND '".$pricemax."'

Link to comment
Share on other sites

ok using your code i get a parse error on this line$SQL = $SQL . 'city='".$city."'' . 'AND';here the errorParse error: parse error, unexpected '"' in C:\Documents and Settings\Marquis Taliaferro\Desktop\web page\results.php on line 32new questionbecause of the fact that im settng the min as 0 the only if statement that could be true is 3. contains min / missing max - $SQL .= 'price>='".$pricemin."''if in the form i set Nomax="" would the if statement to test this beif($_GET["pricemax"]="")

Link to comment
Share on other sites

Im not sure about what you mean mean by min = 0, but try this...im not that good at PHP so you need to fix the syntax...

$pricemin=$_GET["pricemin"];$pricemax=$_GET["pricemax"];if!($pricemin="" && $pricemax="") {$SQL .= "price BETWEEN '".$pricemin."' AND '".$pricemax."'";}else if ($pricemax="") { 'means NO max but has MIN$SQL .= "price >=".$pricemin;}else if($pricemin="") { ' means NO MIN but has MAX$SQL .= "price <=".$pricemax;}'$pricemin="" && $pricemax="" nothing to add the $SQL

Link to comment
Share on other sites

all i was saying about min=0 since im setting min = to zero instead of just leaving it blank it will always have a value so the only if statement that could be possible is the number 3 one you gave me meaning less code for me to writeunforchanly my syntax on php is also very bad it proble going to take a while to fix itthis way is going to take an unreal amount of if statements because of placing the "where" and "ands" cause if you dont get them in the right spot the quiery fails

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...