Re: Searching the database
| From: | Steve Werby | Date: | Mon, 08 Oct 2001 20:58:16 +0000 |
| Subject: | Re: Searching the database | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-70384@lists.php.net to get a copy of this message | ||
"Mick Fitzpatrick" <mick@night-owl.co.uk> wrote:
> I would like to know how to make it search for words mid sentence ... at
the
> moment it will only look at the begining of each entry. So if I type in
> Michael it will display Michael David Smith, Michael Andrew Jones etc etc.
> However, If I type David ... nothing is displayed.
>
> I believe this is the line that defines how the database is searched and I
> believe the fix needs to be there ... but I don't know how to! ... so any
> advice will be appreciated:
>
> $result = mysql_query ("SELECT * FROM example WHERE artists LIKE
'$artists%'
> AND aside LIKE '$aside%' ORDER BY name ASC");
"%" is a wildcard. You need a % at both the beginning and ending of the
string to do the match you want.
SELECT * FROM example WHERE artists LIKE '%$artists%'
AND aside LIKE '%$aside%' ORDER BY name ASC
--
Steve Werby
President, Befriend Internet Services LLC
http://www.befriend.com/