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
Posts: 10Questions: 6Answers: 0
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)