Web lists-archives.com

RE: [PHP] Array to string conversion error help needed




Hi!
> $sth = $pdo->prepare("SELECT * FROM table1 where id IN ($mylist)"
> 
> 
> I get error : Array to string conversion...

That's because you're interpolating an array within a string, and so thearray is bing coerced to a string (giving a meaningless value).
Implode the list into a string and use that instead. For example:
$sth = $pdo->prepare("SELECT * FROM table1 where id IN (" . implode(',', $mylist) . ")";
-Tom