Re: SQL wildcards???
| From: | Chris Aitken | Date: | Wed, 06 Dec 2000 03:18:59 +0000 |
| Subject: | Re: SQL wildcards??? | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-5034@lists.php.net to get a copy of this message | ||
At 10:02 PM 5/12/2000, Gary wrote:
I'm new to PHP, so I have a lot to learn. Is there a way to use any of these string comparisons in a SQL statement? Like (select * from database where field = "some string comparison") I want to find every instance of a word that the user supplies. Are there any wildcard characters I can use? Thanks, GaryIm using mysql as a base for my answer, but its definatly do-able. for example, if I wanted to find every entry that has the color field equal to 'yellow' I would do a query like
select * from TABLE where color='yellow'This would select every field from every entry that has the color set to yellow. But, if you wanted to have a query where it searches for a word anywhere within a field entry, (like searching for a street name in a full address field) then you would....
select * from TABLE where address like '%sunset%'This would select every field from every entry that has the word 'sunset' anywhere in the address field. I hope in not rambling and I dont know whether you are using a different database, but this is the way I do it in mysql. --
Chris Aitken - Webmaster/Database Designer - IDEAL Internetemail: chris@ideal.net.au phone: +61 2 4628 8888 fax: +61 2 4628 8890
--------------------------------------------
Unix -- because a computer's a terrible thing to waste!