phpsqlredbean

Using IN with other conditions in Redbean


I am trying to find some beans by using "IN" as well as "=". I am currently using this code:

$ids = array(1,2,3,4);
$user = 1;

$things = R::find(
  'thing', 
  'id IN ('.R::genSlots($ids).') AND user = ?',
  array(
    $ids,
    $user
  )
);

This gives me some errors:

PHP Notice: Array to string conversion in rb.php on line 217

Fatal error: Uncaught [HY093] - SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens thrown in rb.php on line 267

If I run this code with one item in $id I only get the notice but either way I get no results.

I'm assuming it's trying to treat $id as a single variable. What am I missing?


Solution

  • don't add the $ids to the array, merge the two into one array, otherwise this will end up as a nested array.