PHP code: Comparison with the value of a variable inside WHERE. Is it possible?
PHP code: Comparison with the value of a variable inside WHERE. Is it possible?
The PHP code receives the following variables:
$_POST ['user_id'] - user id
$_POST ['flag_global'] - visibility flag: 0-sees only its own records, 1-sees all records
The logic is as follows:
If $_POST ['flag_global'] == 1, the user sees ALL the records.
If $_POST ['flag_global'] == 0, the user sees entries with the field "user_id_create" = $_POST ['user_id'].
I would like to write this logic inside WHERE, but I do not know how.
Of course, you can initially prescribe:
If ( Если $_POST['flag_global'] == 1 ) {
Editor::inst( $db, 'crm_note' )
….
->process($_POST)
->json();
}
else {
Editor::inst( $db, 'crm_note' )
…
->where( 'user_id_create', $user_id )
->process($_POST)
->json();
}
But then you will have to register a lot of fields twice and then make changes twice when changing the code.
Answers
You can do it like this:
This is obvious at first glance ))) I'm used to the chain. Thank you, Itrac!