How to get all records where column value is equals one of the array elements?
How to get all records where column value is equals one of the array elements?
![vivalaz](https://secure.gravatar.com/avatar/7d385dcba9c54289b9b50dce2dd55035/?default=https%3A%2F%2Fvanillicon.com%2F7d385dcba9c54289b9b50dce2dd55035_200.png&rating=g&size=120)
I have an array $deals_arr = [19300, 19301, 19305]. How to find all records where id_deal is equals one of the array elements? Help, please!
$out = Editor::inst( $db, 'deals' )
->fields(
Field::inst( 'id'),
Field::inst( 'id_deal'),
)
->where(function($q) use($deals_arr) {
$q->where('id_deal', $deals_arr, '=');
})
->process( $_POST )
->json();
This question has accepted answers - jump to:
This discussion has been closed.
Answers
You would need to format your array in a way SQL accepts using the IN statement. And that is
Didn't test this but should work hopefully. The "false" parameter is necessary in order to avoid Editor escaping the sql_arr variable as a string. This way it should pass this thing into the database as is.
forgot to change the use statement ...
use($sql_arr)