Re: searching a MySQL database

From: Date: Sun, 06 May 2001 15:09:56 +0000
Subject: Re: searching a MySQL database
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-51620@lists.php.net to get a copy of this message
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

« previous php.general (#51620) next »