Re: How to determine which column "matched"

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Why so complicated


On Apr 12, 2008, at 5:25 AM, 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:


<?php
$slq = "select producer, designation from wine where designation like '%apple%' and producer like '%apple%' ";
$rs = mysql_query($sql);

while( $row = mysql_fetch_row($rs) ){
   echo $row[0]  ;   // producer
	echo $row[1]  ;   // designation
}

?>



Select producer, flag=1 from wine
where producer like '%apple%'
UNION
Select designation, flag=2 from wine
where designation like '%apple%'



and then in each row that comes back, I could determine which column did that match by doing a PHP analysis of the "flag" value. However, this doesn't appear to be the right way to go about this (mySQL doesn't like these flag=1, flag=2 things.

Can someone help steer me in the right direction?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Igor Jocic
http://www.carster.us/




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux