Re: How to determine which column "matched"
| From: | Robert Cummings | Date: | Sat, 12 Apr 2008 03:42:40 +0000 |
| Subject: | Re: How to determine which column "matched" | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-272917@lists.php.net to get a copy of this message | ||
On Fri, 2008-04-11 at 20:25 -0700, Rob Gould wrote:
> I'm trying to figure out a way that SQL can pass a flag to PHP to say which column
> "matched" during a query.
>
> Let's say for instance that I want to search for the word "apple" in both column
> "producer", and column "designation". I was hoping I could do something like
> this:
>
>
> Select producer, flag=1 from wine
> where producer like '%apple%'
> UNION
> Select designation, flag=2 from wine
> where designation like '%apple%'
<?php
$query =
"SELECT "
." producer, "
." (producer like '%apple%') AS producerMatched "
."WHERE "
." producer like '%apple%' "
."UNION SELECT "
." designation, "
." (designation like '%apple%') AS designationMatched "
."WHERE "
." designation like '%apple%' ";
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP