php + sql search

Jeff LaCoursiere jeff at
Thu Oct 31 13:53:53 GMT 2002

I could be wrong, but I think that you will have to modify your query to
do the search the way you want, which means you will have to parse your
input string and turn it into SQL.  In this case you would have to expand
"cat + dog" to read "(name like '%cat%' or name like '%dog%)".  Note that
using '%' infers a full table scan, and is thus extremely inefficient.  I
think in the case above you will actually do TWO full table scans...  I
don't know how big the table you are searching is; if releatively small
maybe this is not a big deal.  If thousands of records you may have
performance issues.


On Thu, 31 Oct 2002, 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.
> has anyone any ideas?
> many thanks in advance!
> Robin Garbutt
> Portfolio Art & Design Ltd
> Tel -  +44 (0) 1204 383822
> Fax - +44 (0) 1204 383866
> Mob - +44 (0) 7811 185490
> e-mail - Rob at
> For further information please visit us at :-
> The contents of this e-mail are confidential to the ordinary user of the
> e-mail address to which it was addressed and may also be privileged. If you
> are not the addressee of this e-mail you may not copy, forward, disclose or
> otherwise use it or any part of it in any form whatsoever. If you have
> received this e-mail in error please e-mail the sender.
> ------ FreeBSD UK Users' Group  -  Mailing List ------

More information about the Ukfreebsd mailing list