Re: Array Select from database
| From: | A.J. Brown | Date: | Wed, 28 Sep 2005 14:27:19 +0000 |
| Subject: | Re: Array Select from database | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-223355@lists.php.net to get a copy of this message | ||
There is a small bug in your code:
[snip]
$values = join(', ', $array);
$query = "SELECT * FROM client WHERE clientaccountmanager IN ($values)"
[/snip]
You'll need to surround "$values" with a single quote after joining:
[code]
$values = join(', ', $array);
$query = "SELECT * FROM client WHERE clientaccountmanager IN ('$values')"
[/code]
--
Sincerely,
A.J. Brown
"Robin Vickery" <robinv@gmail.com> wrote in message
news:5cb2dafd0509280555e650cc3@mail.gmail.com...
On 9/28/05, Frank Keessen <fkeessen@gmail.com> wrote:
> O.K. Again;
> I have an array with one or more values, which must be selected in the
> database
> Array ( [count] => 1 [0] => Array ( [clientaccountmanager] => Array (
> [count] => 2 [0] => 210 [1] => 149 )
> Now i this is my select..
> I've got the following Query="select * from client WHERE
> clientaccountmanager='$value of array1' OR '$2nd value of array 1'"
>
> How can i loop through the query with all the values out of the array as
> OR
> value..
Are you trying to generate the query from the array?
If so, you are better off using the SQL 'IN' construct.
SELECT * FROM client WHERE clientaccountmanager IN (value1, value2,
value3,...)
Then all you need to do is generate a comma separated list of values
from the array, which you can easily do with join().
$values = join(', ', $array);
Then insert it in your query:
$query = "SELECT * FROM client WHERE clientaccountmanager IN ($values)"
-robin