Slice an array with an inline PDO query

Asked at 2017-01-11 16:10:30Z
  • 5 Subscribers

I'm trying to slice an array but getting an error "array_slice() expects parameter 1 to be array"

Will appreciate any help!

    foreach(array_slice(($pdo->query($query)), 0, 3) as $row_Results) {
       $pic_id = $row_Results['pic_id'];    

1 answers in total

Your Common Sense Posted at 2017-01-11 16:15:12Z

It makes no sense to slice an array returned by SQL query - this should be done in the query itself

 foreach($pdo->query("$query LIMIT 3")) as $row_Results) {
   $pic_id = $row_Results['pic_id'];  

will do the trick.

Answer this questsion