php + sql search

Matthew Seaman m.seaman at
Thu Oct 31 14:00:43 GMT 2002

On Thu, Oct 31, 2002 at 01:35:26PM -0000, Robin Garbutt wrote:
> Hi all,
> I want to be able to query by mysql db with a boolean search.
> at the mo I have:-
> $result = mysql_query("SELECT * FROM db WHERE name LIKE '%$name%'", $db);
> $query_data = mysql_fetch_array($result)
> ideally I would like to be able to type in the search box "something +
> something" to search db with queries like.  Eg. "cat + dog" to return all
> listings containing the words cat and dog.

Funny.  I was just reading O'Reilly handbook on Web Database
Applications.  Assuming you've split your search terms into individual
variables $namea and $nameb, then something like:

    SELECT * FROM db
        WHERE name LIKE '$namea' AND
              name LIKE '$nameb';

but that's just book learning.  (I don't think the leading and
trailing '%' wildcards will do much for you: it's like grep'ing for



Dr Matthew J Seaman MA, D.Phil.                       26 The Paddocks
                                                      Savill Way
Tel: +44 1628 476614                                  Bucks., SL7 1TH UK

More information about the Ukfreebsd mailing list