Re: explode () and mySQL query

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

 



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;

This is the reference in the manual:
http://gr2.php.net/manual/en/function.implode.php

--
Thodoris


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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux