OK,

$cen_fields is an array of a store's Name, City, and State concatenated.

$cen_fields[0] echo'd looks like this: CHIEFS SUPERMARKET ST. MARYS OH 
$cen_fields[1] echo'd looks like this: CHIEFS SUPERMARKET CELINA OH

$in_list is the concatenated store's Name, City, and State but formatted w/ 
commas for MySQL.

i.e.
>From > $in_list = "'".join("','",$cen_chiefs)."'";

$in_list echo'd looks like this:

'CHIEFS SUPERMARKET ST. MARYS OH','CHIEFS SUPERMARKET CELINA OH','CHIEFS 
SUPERMARKET COLDWATER OH','CHIEFS SUPERMARKET DELPHOS OH','CHIEFS 
SUPERMARKET DEFIANCE OH','CHIEFS SUPERMARKET BRYAN OH','CHIEFS SUPERMARKET 
WAUSEON OH','CHIEFS SUPERMARKET PAULDING OH','CHIEFS SUPERMARKET NAPOLEON 
OH'


The central table looks like the following: (There's more columns but to be 
concise I added ones in question)

+--------------------------------+-----------------+----------+
| strName                                    | strCity                 | 
strState |
+--------------------------------+------------------+----------+
| VILLAGE STORE 14 FRESH | WEST PENESIO  | PA       |
| VILLAGE STORE 19 FRESH | WEST PENESIO  | PA       |
| CHIEFS SUPERMARKET      | ST. MARYS         | OH       |
+--------------------------------+-------------------+--------+

So user fills in form.  Table is populated with form data, and if the store 
name, city, and state matches exactly to $in_list value it'll store form 
data in this particular table.

With my current query, rows will be returned only if they match strName, 
strCity, strState exactly.

In addition to that I want the query to return the rows where strName 
matches partial $in_list array value

So if CHIEFS SUPERMARKET ST. MARYS OH is a value in $in_list If user only 
enters "CHIEFS" and not CHIEFS SUPERMARKET I want to be able to return that 
row also, even though it doesn't exactly match array value.

I hope this is more clear.  I tried the MySQL forums but they are kinda slow 
responding.

//============================================================================
""M. Sokolewicz"" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> kvigor wrote:
>> I created an array using the following:
>>
>> $in_list = "'".join("','",$cen_chiefs)."'"; //$cen_chiefs is an array
>>
>> $query_cen_chiefs = "SELECT * FROM central WHERE CONCAT(strName,' 
>> ',strCity,' ',strState) IN({$in_list})";
>>
>> How would I go about adding an AND clause to the above query to return 
>> all rows where strName column values are in $in_list array
>>
>> I acutally did the above w/ "SELECT * FROM central WHERE CONCAT(strName,' 
>> ',strCity,' ',strState)
>> IN({$in_list}) AND (strName) IN({$in_list}) ORDER BY conName"; // This 
>> return zero rows.
>>
>> I think I Should I be using strName as a pattern, because strName would 
>> be a partial value of $in_list array values?
>>
>> Something like: REGEXP '^.....$'
>>
>> "SELECT * FROM central WHERE CONCAT(strName,' ',strCity,' ',strState) 
>> IN({$in_list}) AND (REGEXP '^strName$') IN({$in_list}) ORDER BY conName"; 
>> //This query doesn't work by the way.  This is where I'm stuck.
>
> First of all, let's start by saying that this question is very OT on a 
> php-list. It would be a lot more appropriate on a mysql list. But, I'll 
> try to help you anyway. First of all, I have no clue what you're trying to 
> do. Give some values (ie. what's in $cen_chiefs, what does the central 
> table look like, and what does strName look like.
>
> The whole problem here, afaics, is that you don't have a clear idea of 
> what you want. Tell us what you _want_ to do (not HOW, but what the result 
> should be) and we might be able to help.
>
> Now,
> SELECT * FROM central WHERE CONCAT(strName,' ',strCity,' ',strState) 
> IN({$in_list}) AND (REGEXP '^strName$') IN({$in_list}) ORDER BY conName
> won't work simply because you're saying (php-style): if($foo == $a.' '.$b 
> && $foo == $a), which obviously will _never_ work :) 

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

Reply via email to