WHERE- IN Clause in Editor
WHERE- IN Clause in Editor
davykiash
Posts: 35Questions: 13Answers: 1
Hello,
How do you implement WHERE-IN statements in the server side code of the editor ?
This is what I have (Query in comments)
/*
SELECT id,orderno,ordertime,orderstatus FROM orders
WHERE orderregister = 001
AND orderstatus IN (1,2,3)
*/
json_decode(Editor::inst( $db_details, $table, 'id')
->fields(
Field::inst( 'id' ),
Field::inst( 'orderno' ),
Field::inst( 'ordertime' ),
Field::inst( 'orderstatus' ),
)
->where( 'orderregister', '001', '=' )
->where( 'orderstatus', (1,2,3), 'IN' )
->process($_POST)
->json(false))
);
Thanks.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Hi,
The problem with that is that the
(1,2,3)
is actually "bound" as a string, so the database won't see it as an array. What we need to do is use an anonymous function which provides access to theQuery
class which has more options for controlling the conditions (docs).For example:
Note that although
where
is used in the anonymous function,$q
isQuery
, notEditor
, which is how this works.Allan
Perfect!