Disclaimer: Its late, I'm tired and I haven't tested this code.  Hope it

Quick Overview:

//make your dictionaries all lower case for ease
$countries = array( 1 => 'us', 2 => 'germany', 3 => 'australia' );
$cities = array( 1 => 'new york', 2 => 'berlin', 3 => 'sydney' );
$lodging = array( 1 => 'hotel', 2 => 'motel', 3 => 'inn', 3 => 'bed and
breakfast' );

$query = "hotel germany";

//user will put it in wrong case.

//loop over each array and use it to figure out what column in table to
foreach ($countries as $country) {
        if $country
        if (strstr($query, $country)) {
                $column = "country";
                //need to break out of loop here

Hope it helps and isn't too wrong.  I think you get the idea.  Build up some
data dictionaries that map parts of the input to the columns and the
construct query dynamically.  If you can't figure it out, generate a ui on
the fly asking "By X did you mean?" and then 3 radio buttons to set the
right column.


-----Original Message-----
From: Chris Payne [mailto:[EMAIL PROTECTED]]
Sent: Saturday, March 30, 2002 10:15 PM
Subject: [PHP-DB] Database search question

Hi there everyone,

How can I accomplish the following?

I have a table called search,

I have 3 fields, city, country, type

I also have an imput box where you can type in a search word.  What I need
is, say you type in hotels germany, I need the search to break up the
sentence and then search each 3 fields in the DB looking for a match.

So, for example: it would find hotels in type and germany in country, see
that they belong together and then display those results - how can I do

I know I need to splitup my search phrase into individual words to search,
but i'm stuck.

Thanks for any help.


PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to