Reply to Re: Multiple query variables based on str_word_count

Your name:

Reply:


Posted by Jeff Gardner on 09/27/06 04:28

Kimmo Laine wrote:
> "Jeff Gardner" <null@spamvoid.tld> wrote in message
> news:_ZRRg.5286$e66.3828@newssvr13.news.prodigy.com...
>> Greetings:
>>
>> I am attempting to split an input string using the str_word_count function
>> to return multiple single word query variables.
>> I can create an array based on
>> $search=(str_word_count($search, 1, '0123456789')); (I want words and/or
>> numbers).
>
> Stop right here and go no further with the extract thingy. Here you already
> have a nice beautiful array, arrays are the coolest, aren't they!? Why go
> thru all the trouble with exteracting and such...
>
> You can build up the query conditions with a little implode trick:
>
> $query_conditions =
> " my_field LIKE '%" . implode( "%' OR my_field LIKE '%", $search) . "%'";
>
> now insert $query_condition in your query string:
>
>> $q="
>> SELECT *
>> FROM *
>> WHERE table1.row1
>> LIKE '%$search_x%'
>> OR LIKE '%$search_y%'
>> etc..."
>
>
> HTH
>
This is what ended up working:

$table=array(
'table.column',
'table.column2',
etc...
);

$str = '';
foreach ($search as $s) {
foreach($table as $t){
if ($str != "")
$str .= "OR\n";
$str.= "$t\n" ;
$str .= "LIKE '%$s%'\n";
}}
$q = "
SELECT
$alias
FROM table1
LEFT JOIN table2
ON table1.id = table2.id
WHERE
$str
";

--

Regards,

Jeff Gardner
___________________________

"Contrary to popular belief, Unix is user friendly. It just happens
to be very selective about who its friends are." --Kyle Hearn

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация