Compound WHERE Clause

Compound WHERE Clause

notyou61notyou61 Posts: 21Questions: 8Answers: 0

I need to filter records with more than one parameter to the "WHERE" Clause. I am assuming this would require an "AND" component however am not able to determine how to do it. My code is as follows:

    if (isset($_GET['gridNumber']) && $_GET['gridNumber']==1 && isset($_GET['varAllEmployees']) && $_GET['varAllEmployees']=='y') {
        $editor->where($key = 'userNotVaildDate', $value = '', $op = '!=' ); // Filters for all employees
    } else {
        $editor->where($key = 'userNotVaildDate', $value = '', $op = '=' ); // Filters for terminated and current employees (not correct at present)
    }

Please let me know if any additional information is needed for a solution. Any help is appreciated.

Thanks,

Steve

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,528Questions: 1Answers: 10,473 Site admin

    You can just call where() multiple times :-)

    $editor
      ->where( 'userNotVaildDate', '', '!=' )
      ->where( 'userAdmin', 1 );
    

    Or something like that (depending on your keys :-) ).

    Allan

  • notyou61notyou61 Posts: 21Questions: 8Answers: 0
    edited June 2014

    I would also like to do the following:

        // Process Json
        $editor
            if (isset($_GET['gridNumber']) && $_GET['gridNumber']==1 && isset($_GET['varAllEmployees']) && $_GET['varAllEmployees']=='y') {
                ->where($key = 'userNotVaildDate', $value = '', $op = '=' ) // Filters for current employees
            } else {
                ->where($key = 'userNotVaildDate', $value = '', $op = '!=' ) // Filters for terminated employees
            }
            ->process( $_POST )
            ->json();
    

    However I receive the following error:

    "<b>Parse error</b>: syntax error, unexpected T_IF in "

  • allanallan Posts: 63,528Questions: 1Answers: 10,473 Site admin
    Answer ✓

    The -> operator is a method call in PHP, So you would want to do $editor->where( ... ) etc.

    // Process Json
        if (isset($_GET['gridNumber']) && $_GET['gridNumber']==1 && isset($_GET['varAllEmployees']) && $_GET['varAllEmployees']=='y') {
            $editor->where($key = 'userNotVaildDate', $value = '', $op = '=' ) // Filters for current employees
        } else {
            $editor->where($key = 'userNotVaildDate', $value = '', $op = '!=' ) // Filters for terminated employees
        }
    $editor->process( $_POST )
        ->json();
    

    otherwise, as PHP says, it is a syntax error :-)

    Allan

  • notyou61notyou61 Posts: 21Questions: 8Answers: 0

    Thanks Allan

This discussion has been closed.