Multiple where clauses
Multiple where clauses
coderx
Posts: 45Questions: 7Answers: 0
Hello,
I know I can use where clause as described here: http://editor.datatables.net/docs/current/php/class-DataTables.Editor.html#_where.
And it works as expected. :)
Is it somehow possible to use two or more where clauses? E.g.
Editor::inst( $db, 'table_name' )
->fields( ... ) // other code
->where( $key, $value, $op ) // First where clause
->where_and( $key2, $value2, $op2 ) // Second where clause
->where_or( $key3, $value3, $op3 ) // Third where clause
->process( $_POST )
->json();
This question has accepted answers - jump to:
This discussion has been closed.
Answers
The formatting went wrong.. :(
Editor::inst( $db, 'table_name' )
->fields( ... ) // other code
->where( $key, $value, $op ) // First where clause
->where_and( $key2, $value2, $op2 ) // Second where clause
->where_or( $key3, $value3, $op3 ) // Third where clause
->process( $_POST )
->json();
Hi,
I aded the formatting (doc for how to do it).
The answer is yes, this is possible, but Editor doesn't have
where_and
orwhere_or
methods, which is why your above code doesn't work. TheQuery
class however does, and it can be used in a closure method - but this requires the 1.4 beta (the 1.3 libraries do not support this!).To use you would do something like:
The 1.4 beta is available for download on the Editor downloads page. It will be released as final in the next couple of weeks - just a few .NET things to finish off!
Allan
Hi Allan,
thanks for prompt reply! :) This seems like the solution I was looking for.
Peter
Hi Allan,
I am sorry that I reopen this issue, but I just tried to download newest beta Editor (Editor v1.4 beta.1 - PHP + platform-less) and the recommended solution does not work:
What am I missing?
Peter
Apologies, the correct function names are
and_where
andor_where
(docs). I'll update the code above.Allan
It is strange, but it seems that only the first where works. Is there any full code example in documentation? I was not able to find it.. :(
Note: I mean there is example in http://editor.datatables.net/docs/1.4.0-beta/php/class-DataTables.Database.Query.html#_exec after opening section where( $key, $value = null, $op = "=", $bind = true ), but I was not able to use it successfully.
My code:
I've just tried the following with a simple value and also a closure like you have and it appears to work as expected:
If you code the values into your anonymous function rather than using
global
does it then work?Allan
Shortly: Yes. :) It works now as expected. Thank You, Allan! :)
I redesigned my code in order to use it this way.
More description: non-mandatory reading :)
Just a note for others: It seems that anonymous function
function ($q) { ... }
can not really work withglobal
keyword. My code and results:Interesting! You could use the
use()
option to access external variables instead (see the PHP closure documentation).Allan
Great help, Allan! Thanks! :)
The code is a bit cleaner using the
use()
. :)Peter