Re: [PHP] Array Select from database

2005-09-29 Thread Robin Vickery
On 9/28/05, Silvio Porcellana <[EMAIL PROTECTED]> wrote:
>
> In addiction, I would (SQL)escape the values joined: supposing you are
> using MySQL, I'd do:
> $values = join("', '", array_map('mysql_real_escape_string', $array));

I agree entirely; I was just trying to keep things simple for the OP.

  -robin

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



RE: [PHP] Array Select from database

2005-09-28 Thread Chris W. Parker
Silvio Porcellana 
on Wednesday, September 28, 2005 9:37 AM said:

> In addiction, I would (SQL)escape the values joined: supposing you are
> using MySQL, I'd do:
> $values = join("', '", array_map('mysql_real_escape_string', $array));

Now that's a Freudian slip if I ever saw one. :)

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



Re: [PHP] Array Select from database

2005-09-28 Thread Silvio Porcellana
A.J. Brown wrote:
> 
> [code]
> $values = join(', ', $array);
> $query = "SELECT * FROM client WHERE clientaccountmanager IN ('$values')"
> [/code]
> 
Actually this doesn't seem right, the join should be:
$values = join("', '", $array); # notice the ' inside the "

In addiction, I would (SQL)escape the values joined: supposing you are
using MySQL, I'd do:
$values = join("', '", array_map('mysql_real_escape_string', $array));

HTH, cheers
Silvio

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



Re: [PHP] Array Select from database

2005-09-28 Thread A.J. Brown
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" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
On 9/28/05, Frank Keessen <[EMAIL PROTECTED]> 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 

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



Re: [PHP] Array Select from database

2005-09-28 Thread Robin Vickery
On 9/28/05, Frank Keessen <[EMAIL PROTECTED]> 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

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



Re: [PHP] Array Select from database

2005-09-28 Thread Frank Keessen
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..
 Thanks,
 Frank
On 9/28/05, Jay Blanchard <[EMAIL PROTECTED]> wrote:
>
> [snip]
> Hope you can help me out..
> Array ( [count] => 1 [0] => Array ( [clientaccountmanager] => Array (
> [count] => 2 [0] => 210 [1] => 149 )
>
> I've got the following Query="select * from client WHERE
> clientaccountmanager='$value of array1' OR '$2nd value of array 1'"
> So that the query loops through the whole array...
> [/snip]
>
> OK. Was there a question?
>


RE: [PHP] Array Select from database

2005-09-28 Thread Jay Blanchard
[snip]
 Hope you can help me out..
 Array ( [count] => 1 [0] => Array ( [clientaccountmanager] => Array (
[count] => 2 [0] => 210 [1] => 149 )

I've got the following Query="select * from client WHERE
clientaccountmanager='$value of array1' OR '$2nd value of array 1'"
So that the query loops through the whole array...
[/snip]

OK. Was there a question?

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



[PHP] Array Select from database

2005-09-28 Thread Frank Keessen
Hi All,
 Hope you can help me out..
 Array ( [count] => 1 [0] => Array ( [clientaccountmanager] => Array (
[count] => 2 [0] => 210 [1] => 149 )

I've got the following Query="select * from client WHERE
clientaccountmanager='$value of array1' OR '$2nd value of array 1'"
So that the query loops through the whole array...
  Thanks,
 Frank