PDA

View Full Version : PHP / Ajax / MYSQL Search Form


adammc
10-24-2007, 05:16 AM
Hi Guys,

I am trying to develop a search form for my clients website similiar to this:
http://www.realestate.com.au (http://www.realestate.com.au/cgi-bin/rsearch?s=vic&t=res&snf=rbs&a=sf)

I have a db table of all the Australian Suburbs.
I have a db table of listings categories.
My Listings (what is searched on) contain a category, postcode and suburb row in the listings table in the DB.

I aim to have the following on the search form:
* Input box where the user types in surburbs seperated by commas.
* Combo select box with categories (pulled from db)
* Dropdown list of categories (pulled from DB)

Users would need to be able to have multiple choices for the category combo box and category input box.

How would I begin to create the ajax type style functionality for my search form as found on the link above?

Any help would be greatly appreciated :)

pemcconnell
10-24-2007, 09:36 AM
what is the ajax for? Are you wanting to preload the entire db and have results display as you type, or something to that effect?

As far as the suburbs being entered seperated with commas, I would use explode ( , ) on the entire string, then trim, then SQL WHERE LIKE %searchterm% - also I would make sure that your db is a full-indexed table if any searching is to be performed.

pemcconnell
10-24-2007, 09:40 AM
#EDIT#

As far as the combo select box, assign them all the values of the associated id in the database, make sure they are all under the same name / id, and pass it into your WHERE statement:

if($_REQUEST['combo']!=""){
$sql .= " WHERE a='".$_REQUEST['combo']."'";
}

pemcconnell
10-24-2007, 09:58 AM
Sorry about the lengthy stringing going on but the edit message is timing out for some reason

orgional message altered:

what is the ajax for? Are you wanting to preload the entire db and have results display as you type, or something to that effect?

As far as the suburbs being entered seperated with commas, I would use explode ( , ) on the entire string, then trim, then SQL WHERE x LIKE %searchterm%".....

This would probibly be easier:

OR SQL WHERE x IN searchterm <- keep the orgional string, without explode - also I would make sure that your db is a full-indexed table if any searching is to be performed. Either way (WHERE x IN / WHERE x LIKE %%) has different benefits - i'd look into em both

aedrin
10-24-2007, 05:11 PM
OR SQL WHERE x IN searchterm <- keep the orgional string, without explode

This will:

1. Not work

2. If it did work, would be a really bad solution.

http://en.wikipedia.org/wiki/Database_normalization

* Combo select box with categories (pulled from db)
* Dropdown list of categories (pulled from DB)

A dropdown is the same as a combo box. You would use a SELECT element here that allows multiple selection.

Real estate websites that force me to choose one category of housing to search for, are worthless.

If you end up using that solution, you would have to gather all the selected IDs, then use the IN keyword in SQL to join the different tables.