or_where condition in php
or_where condition in php
orik3ll0
Posts: 36Questions: 12Answers: 2
Hello all.
Here is my SQL where date > '$todaydate1' or (date > '$yesterday' and time >= '$time') and I need to write it in editor. How it should work? I took code from forums and it is not working even without or.
->where( function ( $q ) {
$q
->where( 'date', $todaydate1, '=' )
->or_where( function ( $r ) {
$r->where( 'date', $yesterday);
$r->where( 'time', $time, '>=' );
} );
} )
This discussion has been closed.
Answers
@allan Dear Allan, I took this code from your comment. Can you advice me something?
You don't describe what exactly is not working and what the error message is. Hard to answer your question like this but I'll try.
First I'd recommend you read this about PHP variable scope:
http://php.net/manual/en/language.variables.scope.php
I'd recommend to use Superglobals like $_SESSION to use in functions which you can't pass parameters into.
$yesterday won't work like this. Neither will $time and $todaydate1
This is also helpful I guess:
https://datatables.net/forums/discussion/comment/108731#Comment_108731
Yup - if those variables need to be passed in, have a look at my comment that @rf1234 linked to.
Allan