RE: [PHP] mysql Pattern Matching
| From: | Ralph Guzman | Date: | Fri, 05 Sep 2003 11:23:41 +0000 |
| Subject: | RE: [PHP] mysql Pattern Matching | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-161736@lists.php.net to get a copy of this message | ||
Is there an advantage or difference in running FIND_IN_SET() instead of
LIKE?
-----Original Message-----
From: CPT John W. Holmes [mailto:holmes072000@charter.net]
Sent: Thursday, September 04, 2003 5:53 AM
To: Ralph Guzman; PHP General Mailing List
Subject: Re: [PHP] mysql Pattern Matching
From: "Ralph Guzman" <ralph213@sbcglobal.net>
> I know this question is best for the mySQL mailing list, but I am
unable
> to subscribe to their list at this moment so perhaps somebody here can
> help me out.
>
> I have a table with a field where amenities are listed together using
a
> comma delimiter like: pool,spa,fitness-center
>
> To search this table I use a query that looks something like this:
>
> SELECT * FROM properties WHERE amenities LIKE '%pool%' AND amenities
> LIKE '%spa%' AND amenities LIKE '%fitness-center%'
>
> This works, however let's say the user chooses to search for more
> amenities. This means the query would need multiple 'AND amenities
LIKE
> '%____%' statements.
>
> Is there a better way to write this?
You could use FIND_IN_SET().
SELECT * FROM properties WHERE FIND_IN_SET('pool',amenities) AND
FIND_IN_SET('spa',amenities) AND ...
It'll still grow as the number of amentities grow, but there's no
getting
around that.
---John Holmes...
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php