On Sun, 6 May 2001, Jamie Saunders wrote:

> Hi,
>
> I've set up a MySQL database and an HTML search form.  I'd like to know how
> to search the database with whatever it entered into the form.  It only
> needs to be a simple search, returning anything that matches the word(s)
> entered into the input box in the form.  Thanks.

Yes, I would like to know how people are doing this too. I have a database
where columns in multiple tables are searched for multiple keywords. The
statement ends up lookup like this for the entered keyword: 'this or that'
(the REGEXP prevents partial word matches, like 'hunk' in 'chunky') if you
want the source for this part, email me privately...

SELECT dates.date, dates.time, dates.city, dates.location, dates.contact,
dates.phone, dates.eventid, dates.id ,events.title, events.descrip,
events.speaker, events.attr, events.id

FROM dates, events

WHERE dates.eventid = events.id
  AND (
        (
          ( dates.city REGEXP '[[:<:]]this[[:>:]]' )
       OR (dates.location REGEXP '[[:<:]]this[[:>:]]' )
       OR (events.title REGEXP '[[:<:]]this[[:>:]]' )
       OR (events.descrip REGEXP '[[:<:]]this[[:>:]]' )
       OR (events.speaker REGEXP '[[:<:]]this[[:>:]]' )
       OR (events.attr REGEXP '[[:<:]]this[[:>:]]' )
        )
     OR (*note) (
          ( dates.city REGEXP '[[:<:]]that[[:>:]]' )
       OR (dates.location REGEXP '[[:<:]]that[[:>:]]' )
       OR (events.title REGEXP '[[:<:]]that[[:>:]]' )
       OR (events.descrip REGEXP '[[:<:]]that[[:>:]]' )
       OR (events.speaker REGEXP '[[:<:]]that[[:>:]]' )
       OR (events.attr REGEXP '[[:<:]]that[[:>:]]' )
        )
     )
AND date LIKE '2001-05%'
ORDER BY date

(*note): this would have been AND if the keyword was 'this and that'

is this how it is generally done or am I way off here? :)

cheers,
bill


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to