Multiselct values if they are in either Column01 OR Column02?

Multiselct values if they are in either Column01 OR Column02?

CapamaniaCapamania Posts: 233Questions: 81Answers: 5
edited April 2016 in Editor

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

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    where_group defaults to AND. You need to use the second optional values of where_group to set it to be OR: docs.

    Allan

  • CapamaniaCapamania Posts: 233Questions: 81Answers: 5

    Love it. Excellent, many thanks!

This discussion has been closed.