You are here:

DHTML/searching.....

Advertisement


Question
Hi Andrew,
OK... you know how you can go to a realtor website and do a search for exactly what you want?
I need some code to do that. I need a search form on my index page and I need to know where to put keywords I'm supposed to put on each individual page that will bring up those pages as results. Does this make any sense to you?
I've very good with HTML, but only familiar with javascript (i'm a cut and paste and edit... I can't code it myself).. I've searched dynamicdrive.com and can't find what I'm looking for.. maybe this code is not javascript, maybe it's c++?? I don't know... anyway, I think it's an if then code... anyway, any help you can give me would be great.

Thanks,
Christina

Answer
Hi Christina-

JavaScript or HTML cannot help you at all for this question.  C++ is not really the right way either.  You should use a server-side language like PHP or ASP for this.  Basically, you'll have a database containing all the locations, prices, etc., that represent the objects people are searching for.  You may offer people an ability to run searches that translate to English questions like this:

"Show me all homes in California under $120,000."

So your users will fill in an HTML form you create, where the action attribute in the form will point to some server-side processing file.  We'll call this file process.php, if you choose to go the PHP route.  You're basically passing this file different parameters sent in by your user.  PHP gathers the users answers like this:

$some_variable = $_POST['location'];

In this case, '$some_variable' will contain whatever value was selected by the user; this might be a select box.

<select name='location'>
<option>CA</option>
<option>PA</option>
<option>etc.</option>
</select>

Once you have the user's selection, you'll build a query and "ask" the database for a recordset of answers.  The query might look something like this:

"SELECT * from properties where price < 120000 AND location = 'CA'";

That might answer this query:

"Show me all homes in California under $120,000."

Do you see yet how there is no way you could build enough if/then statements to satisfy every possible user question?  You would need a high-powered computer to compute all the possible questions that could be asked; this could reach well into the billions of possibilities.  That's why we have relational databases to make arriving at specific results much less time-consuming.

I understand this is a very shallow tutorial on server-side processing and doesn't exactly answer your question(s).  However, this AllExperts section is really for DHTML, a completely client-side endeavor, so my answer could be worse.  Google around for beginning server-side processing tutorials.  There are some nice ones out there.  I recommend the following URLs:

http://www.keithjbrown.co.uk/vworks/php/php_p1.php
http://www.freewebmasterhelp.com/tutorials/phpmysql

If you get stuck, try asking a question in our PHP section.

Best of luck,
Andrew  

DHTML

All Answers


Answers by Expert:


Ask Experts

Volunteer


Andrew Hoffman

Expertise

Ask me about JavaScript, CSS, HTML5/XHTML, or PHP. Chances are I'll be able to help you. I know the economy is in the tank, but if you like my answer, please consider donating a few bucks. It's like tipping your barista, if your barista served fresh code instead of coffee.

Experience

I started doing this when boy bands were still cool.

Education/Credentials
I read a lot of nerdy books to get here.

©2012 About.com, a part of The New York Times Company. All rights reserved.