How to formulate where or statement, simple question

How to formulate where or statement, simple question

panzrampanzram Posts: 29Questions: 11Answers: 0

Hi,

I need the following sql:

SELECT * FROM x WHERE A=1 OR B=1

In my php file I can write

->where( 'A', 1, '=' )
->process( $_POST )
->json();

For a simple where, but how do I add the OR B=1?

This question has an accepted answers - jump to answer

Answers

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    I believe that the Editor has an "orwhere" method.

    ->where( 'A', 1, '=' )
    ->orwhere( 'B', 1, '=' )
    ->process( $_POST )
    ->json();
    

    I may be wrong, so read the docs.

  • panzrampanzram Posts: 29Questions: 11Answers: 0

    Thx, I tried both orwhere and or_where (which I did find a reference to), but it didn't work...

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

    There isn't actually an or_where method on the Editor class - it exists on the Query class. So you'd need to use a closure function to be able to modify the query.

    This is documented in the manual which a specific section on going exactly what you are looking for.

    ->where( function ( $q ) {
        $q
            ->where( 'A', '1' )
            ->or_where( 'B', '1' );
    } );
    

    Regards,
    Allan

  • panzrampanzram Posts: 29Questions: 11Answers: 0

    Excellent. Thank you for your, as always, relevant reply.

This discussion has been closed.