Re: [PHP-DB] explode () and mySQL query

[email protected] (Chris)
Newsgroups php.db
Message-ID <[email protected]>
Thodoris wrote:
> O/H Ron Piggott ??????:
>> I am trying to add a search feature to my shopping cart.
>>
>> I am wanting to use PHP to develop the query for mySQL.  I have the
>> following code figured out:
>>
>> foreach(explode(" ", $keyword) as $key) $query .= " $key, ";
>>
>> This produces:
>>
>> WHERE shopping_cart_product.product_description IN ( Jesus, is, Lord, )
>>
>> The weakness is the trailing , after the last word the user types in.
>>
>> How can I eliminate this?
>>
>> Ron
>>
>>
>>   
> You can alternative use implode which I think is a much better choice
> because it does exactly what you need.
> You can use it like this
> 
> $keys = implode(",",$keyword);
> $query .= $keys;

Not really - because it'll create an invalid sql query. Even if you put
quotes around it, it would be prone to sql injection (search for o'malley).

-- 
Postgresql & php tutorials
http://www.designmagick.com/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.