NEW TO PHP, PLEASE HELP!
Posted: Sun Oct 26, 2008 11:52 pm
I am working on a real estate website, and I am having some difficult with a part of my search function. On the search page, you can either search by city, state, or zip code, and I have an area where you can search a price range, number of bedrooms, and number of bathrooms. haven't gotten to the bed and bath section, but I can seem to get the price range to work. If someone could help that would be great. Also, if you can tell me in what direction to go with the whole bed and bath thing, that would be great as well. Thanks in advanced.
Below is the code for that portion of my site:
Below is the code for that portion of my site:
Code: Select all
<?php
include('db_connect.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Listing</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<SCRIPT LANGUAGE="JavaScript">
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=600,height=500,left = 302,top = 134');");
}
</SCRIPT>
</head>
<body>
<?php
if (isset($_GET['search']) || isset($_GET['min']) || isset($_GET['max']))
{
?>
<table align="center" cellpadding="0" cellspacing="0" style="background-color:#FFFFFF;">
<tr>
<td colspan="8">
<img src="../images/header.jpg" />
</td>
</tr>
<tr>
<td><a href="index.php" id="bnt1"></a></td>
<td><a href="#" id="bnt2"></a></td>
<td><a href="forsale.php" id="bnt3"></a></td>
<td><a href="#" id="bnt4"></a></td>
<td><a href="#" id="bnt5"></a></td>
<td><a href="#" id="bnt6"></a></td>
<td><a href="#" id="bnt7"></a></td>
<td><a href="#" id="bnt8"></a></td>
</tr>
<tr><td> </td></tr>
<tr>
<td colspan="8">
<table width="750px" align="center" cellpadding="0" cellspacing="0" style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10pt;">
<tr>
<td>
<fieldset style="border:solid 1px #000000;">
<legend style="color:#666666; font-size:14pt;">Search Results</legend>
<table width="100%">
<tr>
<td align="center" colspan="2">
Click on the image to view more information on each listing.
</td>
</tr>
<tr><td> </td></tr>
<?php
$query = "SELECT * FROM `listing` WHERE `zip` LIKE '%".$_GET['search']."%' OR `city` LIKE '%".$_GET['search']."%' OR `state` LIKE '%".$_GET['search']."%' OR `price` >= '%".$_GET['min']."%' AND `price` <= '%".$_GET['max']."%'";
$result = mysql_query($query) or die(mysql_error());
while (($row = mysql_fetch_array($result)))
{
$price = $row['price'];
$price = number_format($price);
?>
<tr>
<td width="125px">
<a href="javascript:popUp('listing_info.php<?php echo '?id='.$row['autoid']; ?>')"><img src="../images/house-selling-1.jpg" width="165" height="134" /></a> </td>
<td valign="top">
$<?php echo "$price"; ?><br />
<?= $row['address'] ?><br />
<?= $row['city'] ?>, <?= $row['state'] ?> <?= $row['zip'] ?><br />
<?= $row['bed'] ?> Bedroom, <?= $row['bath'] ?> Bath<br />
<?= $row['short'] ?><br />
</td>
</tr>
<tr>
<td colspan="2">
<hr size="1" color="#000000" />
</td>
</tr>
<?php
}
?>
</table>
</fieldset>
</td>
</tr>
<tr><td> </td></tr>
<tr>
<td colspan="8" align="center" style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:8pt; color:#999999;">
<a href="index.php" id="link">Home</a> | Sell Your Home | <a href="listing.php" id="link">Homes For Sale</a> | Testimonials | Mortgage | Title | Learning Center | Contact | <a href="admin_login.php" id="link">Admin</a>
</td>
</tr>
<tr><td> </td></tr>
</table>
</td>
</tr>
</table>
<?php
exit();
}
?>
<?php
if (isset($_GET['all']))
{
?>
<table align="center" cellpadding="0" cellspacing="0" style="background-color:#FFFFFF;">
<tr>
<td colspan="8">
<img src="../images/header.jpg" />
</td>
</tr>
<tr>
<td><a href="index.php" id="bnt1"></a></td>
<td><a href="#" id="bnt2"></a></td>
<td><a href="forsale.php" id="bnt3"></a></td>
<td><a href="#" id="bnt4"></a></td>
<td><a href="#" id="bnt5"></a></td>
<td><a href="#" id="bnt6"></a></td>
<td><a href="#" id="bnt7"></a></td>
<td><a href="#" id="bnt8"></a></td>
</tr>
<tr><td> </td></tr>
<tr>
<td colspan="8">
<table width="750px" align="center" cellpadding="0" cellspacing="0" style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10pt;">
<tr>
<td>
<fieldset style="border:solid 1px #000000;">
<legend style="color:#666666; font-size:14pt;">Listings</legend>
<table width="100%">
<tr>
<td align="center" colspan="2">
Click on the image to view more information on each listing.
</td>
</tr>
<tr><td> </td></tr>
<?php
$query = 'SELECT * FROM `listing` ORDER BY `autoid` DESC';
$result = mysql_query($query) or die(mysql_error());
while (($row = mysql_fetch_array($result)))
{
$price = $row['price'];
$price = number_format($price);
?>
<tr>
<td width="125px">
<a href="javascript:popUp('listing_info.php<?php echo '?id='.$row['autoid']; ?>')"><img src="../images/house-selling-1.jpg" width="165" height="134" /></a> </td>
<td valign="top">
$<?php echo "$price"; ?><br />
<?= $row['address'] ?><br />
<?= $row['city'] ?>, <?= $row['state'] ?> <?= $row['zip'] ?><br />
<?= $row['bed'] ?> Bedroom, <?= $row['bath'] ?> Bath<br />
<?= $row['short'] ?><br />
</td>
</tr>
<tr>
<td colspan="2">
<hr size="1" color="#000000" />
</td>
</tr>
<?php
}
?>
</table>
</fieldset>
</td>
</tr>
<tr><td> </td></tr>
<tr>
<td colspan="8" align="center" style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:8pt; color:#999999;">
<a href="index.php" id="link">Home</a> | Sell Your Home | <a href="listing.php" id="link">Homes For Sale</a> | Testimonials | Mortgage | Title | Learning Center | Contact | <a href="admin_login.php" id="link">Admin</a>
</td>
</tr>
<tr><td> </td></tr>
</table>
</td>
</tr>
</table>
<?php
} else {
?>
<table align="center" cellpadding="0" cellspacing="0" style="background-color:#FFFFFF;">
<tr>
<td colspan="8">
<img src="../images/header.jpg" />
</td>
</tr>
<tr>
<td><a href="index.php" id="bnt1"></a></td>
<td><a href="#" id="bnt2"></a></td>
<td><a href="forsale.php" id="bnt3"></a></td>
<td><a href="#" id="bnt4"></a></td>
<td><a href="#" id="bnt5"></a></td>
<td><a href="#" id="bnt6"></a></td>
<td><a href="#" id="bnt7"></a></td>
<td><a href="#" id="bnt8"></a></td>
</tr>
<tr><td> </td></tr>
<tr>
<td colspan="8">
<table width="750px" align="center" cellpadding="0" cellspacing="0" style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10pt;">
<tr>
<td style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12pt;">
<a href="<?= $_SERVER['PHP_SELF'] ?>?all" id="link">View All Listings</a>
</td>
</tr>
<tr><td> </td></tr>
<tr>
<td>
<table align="center" width="452px">
<tr>
<td>
<fieldset style="border:solid 1px #000000;">
<legend style="color:#666666; font-size:14pt;">Search</legend>
<table width="100%" align="center">
<tr>
<td style="font-size:10pt; font-family:Verdana, Arial, Helvetica, sans-serif; color:#999999;" width="300px">
<form action="<?= $_SERVER['PHP_SELF'] ?>" enctype="multipart/form-data" method="get">
<center><input type="text" name="search" onfocus="if(this.value=='Search')this.value='';" onblur="if(this.value=='')this.value='Search';" size="50px" value="Search" /> <br />
Enter City, State or Zip Code</center><br /><br />
<font color="#000000"> Price Range:<br />
<center>
From: <input type="text" name="min" /> To: <input type="text" name="max" /><br /><br />
Bedrooms:
<select name="bed">
<option value="" selected="selected"></option>
<option value="1">1+</option>
<option value="2">2+</option>
<option value="3">3+</option>
<option value="4">4+</option>
<option value="5">5+</option>
</select>
Baths:
<select name="bath">
<option value="" selected="selected"></option>
<option value="1">1+</option>
<option value="1.5">1.5+</option>
<option value="2">2+</option>
<option value="2.5">1.5+</option>
<option value="3">3+</option>
<option value="3.5">1.5+</option>
<option value="4">4+</option>
<option value="4.5">1.5+</option>
<option value="5">5+</option>
</select>
</center>
</font>
<div style="text-align:right;"><input type="submit" value="Search" /></div>
</form>
</td>
</tr>
</table>
</fieldset>
</td>
</tr>
</table>
</td>
</tr>
<tr><td> </td></tr>
<tr>
<td colspan="8" align="center" style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:8pt; color:#999999;">
<a href="index.php" id="link">Home</a> | Sell Your Home | <a href="forsale.php" id="link">Homes For Sale</a> | Testimonials | Mortgage | Title | Learning Center | Contact | <a href="realestate_admin.php" id="link">Admin</a>
</td>
</tr>
<tr><td> </td></tr>
</table>
</td>
</tr>
</table>
<?php
}
?>
</body>
</html>