Re: Selecting Rows Based on Row Values Being in Array

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

 



This is working so far but I need to add an additional search.

This is what I have so far:

$in_list = "'".join("','",$cen_chiefs)."'";

$query_cen_chiefs = "SELECT * FROM central WHERE CONCAT(strName,' 
',strCity,' ',strState) IN({$in_list}) ORDER BY conName";

I also need the query to return records where strName values are in 
$cen_chiefs

I tried query 5 different ways and none return any records except for one 
above.
This is one that failed:

"SELECT * FROM central WHERE CONCAT(strName,' ',strCity,' ',strState) 
IN({$in_list}) AND WHERE (strName) IN({$in_list}) ORDER BY conName";

Any suggestions?


"Jim Lucas" <lists@xxxxxxxxx> wrote in message 
news:4685FDE7.8000703@xxxxxxxxxxxx
> K. Hayes wrote:
>> Will do.  Thanks.
>>
>>
>> ----- Original Message ----- From: "Jim Lucas" <lists@xxxxxxxxx>
>> To: "kvigor" <k3cheese@xxxxxxxxxxxxx>
>> Cc: <php-general@xxxxxxxxxxxxx>
>> Sent: Saturday, June 30, 2007 1:46 AM
>> Subject: Re:  Selecting Rows Based on Row Values Being in Array
>>
>>
>>> kvigor wrote:
>>>> Hello All,
>>>>
>>>> I'm attempting to return rows from a mysql DB based on this criteria:
>>>>
>>>> I have a list, in the form of an array that I need to compare against 
>>>> each row
>>>> in the table.  Where theres a match I need that entire row returned.
>>>>
>>>> e.g.    $varListof 3outOf_10Fields = array(6blue40lbs, 7orange50lbs, 
>>>> 8orange60lbs, 9purple70lbs);
>>>>
>>>> The array contains 3 of the db row fields in 1 value. However there are 
>>>> 10 fields/columns in the table.
>>>>
>>>> ===============
>>>> what table looks like  |
>>>> ===============
>>>>                   size       color    weight
>>>> ROW 1    | value1 | value1 | value1 | value1 | value1 | value1 |
>>>>
>>>> So how could I set up a query that would SELECT the entire row, if the 
>>>> row contained $varListof 3outOf_10Fields[1].
>>>>
>>>> Open to any suggestions or work arounds.  I'm playing with extract() 
>>>> but code is too crude to even post.
>>>>
>>> I would suggest approaching the problem with a slightly different 
>>> thought.
>>>
>>> just have the sql concat() the columns together and then compare.
>>>
>>> something like this should do the trick
>>>
>>> $list = array(
>>> '6blue40lbs',
>>> '7orange50lbs',
>>> '8orange60lbs',
>>> '9purple70lbs',
>>> );
>>>
>>> $SQL = "
>>> SELECT *
>>> FROM my_Table
>>> WHERE CONCAT(value1, value2, value3) IN ('".join("','", $list)."')
>>> ";
>>>
>>> mysql_query($SQL);
>>>
>>> this should take, for each row in the DB, value1 + value2 + value3 and 
>>> create one string from them, then it will compare each string in the
>>> IN (...)  portion to each entry in the $list array().
>>>
>>> Let me know if you need any further help
> one other thing, make sure that you run each of the values in the $list 
> array() through mysql_real_escape_string().  That way it is all nicely 
> encoded for the SQL statement. 

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


[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