I’m working on a real estate listing website. One of the key features of the site is an open house “search”. I’m trying to determine the best way to build the search feature. The database is mySQL. I’m using PHP to build the site. I can connect to the database to input data, update data and pull data directly from tables and fields, but can’t find the best way to perform a search based on a query of multiple fields.
After each search, I want the results to be displayed in a table, 10 per page.
I’ve spent more than a few days trying to do this. Is there any tutorial, sample code or demo available that will help? Thanks!
Here's the code to my simple prototype search form.
<body>
<table width="500" border="0" align="center" cellpadding="6" cellspacing="6">
<tr>
<td valign="top" class="body-text"><p align="center">Open House Search</p>
<form id="form3" name="form3" method="post" action="">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="middle" class="body-text"><div align="right" class="body-text10">
<div align="right">Property Type:<img src="images/spacer.gif" width="6" height="4" /> </div>
</div></td>
<td width="141" height="35" valign="middle"><label>
<select name="propType" id="propType">
<option selected="selected">All Property Types</option>
<option>Single Family</option>
<option>Townhouse/Condo</option>
<option>Multi Family</option>
</select>
</label></td>
</tr>
<tr>
<td valign="middle" class="body-text"><div align="center" class="body-text10">
<div align="right">Open House Dates:<img src="images/spacer.gif" width="6" height="4" /> </div>
</div></td>
<td height="35" valign="middle"><label>
<select name="openDates" id="openDates">
<option selected="selected">April 2008</option>
<option>May 2008</option>
<option>June 2008</option>
<option>July 2008</option>
</select>
</label></td>
</tr>
<tr>
<td valign="middle" class="body-text"><div align="center" class="body-text10">
<div align="right">List Price:<img src="images/spacer.gif" width="6" height="4" /> </div>
</div></td>
<td height="35" valign="middle"><label>
<select name="listPrice" id="listPrice">
<option selected="selected">$100,000 or less</option>
<option>$101,000 to $150,000</option>
<option>$151,000 to $200,000</option>
<option>$201,000 to $250,000</option>
<option>$251,000 to $300,000</option>
<option>351,000 to $400,000</option>
<option>$401,000 to $450,000</option>
<option>$451,000 to $500,000</option>
<option>$501,000 to $600,000</option>
</select>
</label></td>
</tr>
<tr>
<td valign="middle" class="body-text10"><div align="right">Number of Bedrooms:<img src="images/spacer.gif" width="6" height="4" /></div></td>
<td height="35" valign="middle"><label>
<select name="bed" id="bed">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
</select>
</label></td>
</tr>
<tr>
<td valign="middle" class="body-text10"><div align="right">Number of Bathrooms:<img src="images/spacer.gif" width="6" height="4" /></div></td>
<td height="35" valign="middle"><label>
<select name="bath" id="bath">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
</select>
</label></td>
</tr>
<tr>
<td valign="middle" class="body-text"><div align="center" class="body-text10">
<div align="right">Number of Garage Spaces:<img src="images/spacer.gif" width="6" height="4" /></div>
</div></td>
<td height="35" valign="middle"><label>
<select name="garage" id="garage">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
</select>
</label></td>
</tr>
<tr>
<td valign="middle" class="body-text10"><div align="right">Living Space Sq. Ft.:<img src="images/spacer.gif" width="6" height="4" /> </div></td>
<td height="35" valign="middle"><label>
<select name="squareFeet" id="squareFeet">
<option selected="selected">1,000 or less</option>
<option>1,001 to 1,500</option>
<option>1,501 to 2,000</option>
<option>2,001 to 2,500</option>
<option>2,501 to 3,000</option>
<option>3,001 to 3,500</option>
<option>3,501 to 4,000</option>
<option>4,001 to 4,500</option>
<option>4,501 to 5,000</option>
<option>5,001 to 5,500</option>
<option>5,501 to 6,000</option>
<option>6,000 or more</option>
</select>
</label></td>
</tr>
</table>
<p align="center">
<input name="Submit" type="submit" id="Submit" value="Submit Search" />
</p>
</form> </td>
</tr>
</table>
<form id="form2" name="form2" method="post" action="">
<div align="center"></div>
</form>
</body>