Another where & and question

Another where & and question

RappiRappi Posts: 82Questions: 18Answers: 1

Hi.
I need the following sql select:

SELECT * FROM tm_tiere WHERE Geloescht=0 AND Schutzgebuehr=0 AND (Adoptant!=0 OR Vermitteltdatum!=0000-00-00

When I use

->where( function ( $q ) {
    
        $q ->where( 'tm_tiere.Schutzgebuehr', '0', '=');
        $q ->where( 'tm_tiere.Geloescht',' 0', '=');
        
        $q ->where( 'tm_tiere.Adoptant', '0', '!=' );
        $q ->or_where( 'tm_tiere.Vermitteltdatum', '0000-00-00', '!=');
        
    } )

The OR select is working but the Schutzgebuehr=0 don't work.

With

->where( function ( $q ) {
    
        $q ->where( 'tm_tiere.Schutzgebuehr', '0', '=');
        $q ->where( 'tm_tiere.Geloescht',' 0', '=');
        
        //$q ->where( 'tm_tiere.Adoptant', '0', '!=' );
        //$q ->or_where( 'tm_tiere.Vermitteltdatum', '0000-00-00', '!=');
        
    } )

it shows me the entrys with Schutzgebuehr=0 AND Geloescht=0

How can I make my needed select?

Regards

Rappt

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,695Questions: 1Answers: 10,500 Site admin
    Answer ✓

    Hi Rappt,

    You've already got one closure - you need another (in the context of the where condition a closure basically equates to being brackets):

    ->where( function ( $q ) {
         
            $q ->where( 'tm_tiere.Schutzgebuehr', '0', '=');
            $q ->where( 'tm_tiere.Geloescht',' 0', '=');
            $q->where( function ( $q2 ) {
                    $q2 ->where( 'tm_tiere.Adoptant', '0', '!=' );
                    $q2 ->or_where( 'tm_tiere.Vermitteltdatum', '0000-00-00', '!=');
            } );
        } )
    

    Allan

  • RappiRappi Posts: 82Questions: 18Answers: 1

    Great!
    Thanks Allan.

This discussion has been closed.