PHP (here if statement) in server side script possible?

PHP (here if statement) in server side script possible?

RappiRappi Posts: 82Questions: 18Answers: 1

Hi.

I give some variables to my server side script and want to make a where condition only if variable is set.

Can I make a php if statement in this script? Or is there another solution?

I need this and this is not working:

if($aktiv == '1'){
         ->where( 'tm_pflegestellen.Aktiv', $aktiv, '=')
}
if($schulung == '1'){
         ->where( 'tm_pflegestellen.Schulung', '0000-00-00', '=')
}

Thanks
Rappi

This question has accepted answers - jump to:

Answers

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

    You would just break the chain:

    $editor = new Editor( ... )
      ->fields( ... );
    
    if($aktiv == '1'){
             $editor->where( 'tm_pflegestellen.Aktiv', $aktiv, '=')
    }
    
    $editor->process( $_POST );
    $editor->json();
    

    Allan

  • RappiRappi Posts: 82Questions: 18Answers: 1

    Great!
    Thanks Allan.

  • RappiRappi Posts: 82Questions: 18Answers: 1

    I'am again.

    Now I have all working but the OR condition isn't working :-(

    Can you help me one more time, please?

    if($tierart != '0'){
            $editor->where( function ( $q ) {
                $q ->where( 'tm_pflegestellen.Tierart', $tierart, '=');
                $q ->or_where( 'tm_pflegestellen.Tierart2', $tierart, '=');
            } );
        }
    

    it show an error "Notice: Undefined variable tierart in these lines:

    $q ->where( 'tm_pflegestellen.Tierart', $tierart, '=');
    $q ->or_where( 'tm_pflegestellen.Tierart2', $tierart, '=');
    

    I think the reason is the missing $editor ?!?

    But how can I write this function otherwise?

    Rappi

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

    You need to use the use statement in PHP to accessible variables inside anon functions. See the PHP documentation.

    Allan

This discussion has been closed.