Multiselct values if they are in either Column01 OR Column02?
Multiselct values if they are in either Column01 OR Column02?
How can I multiselct values if they are in either Column01 OR Column02?
Based on https://datatables.net/forums/discussion/33433/sending-multiple-values-via-ajax-data-to-editor-where-end-looping-through-where
As of right now, the below only returns the value if it is in Column01 AND in Column02:
->where( function ($f) {
if ( is_array( $_POST["selectValue"] ) ) {
$f->where_group( true );
for ( $i=0, $ien=count($_POST["selectValue"]) ; $i<$ien ; $i++ ) {
$f->or_where( 'Column01', $_POST["selectValue"][$i] );
}
$f->where_group( false );
}
} )
->where( function ($g) {
if ( is_array( $_POST["selectValue"] ) ) {
$g->where_group( true );
for ( $i=0, $ien=count($_POST["selectValue"]) ; $i<$ien ; $i++ ) {
$g->or_where( 'Column02', $_POST["selectValue"][$i] );
}
$g->where_group( false );
}
} )
Yet, I want to have something similar to (as in the example):
$editor->where( function ( $q ) {
$q
->where( 'age', '18', '>' )
->or_where( function ( $r ) {
$r->where( 'name', 'Allan' );
} );
} );
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
where_group
defaults toAND
. You need to use the second optional values ofwhere_group
to set it to beOR
: docs.Allan
Love it. Excellent, many thanks!