where conditions with an array

where conditions with an array

alord84alord84 Posts: 24Questions: 15Answers: 1

Is there a way to do this in the server script
<?php $arrayA=(1,2,3,4,5,6,7,8,...,100); ?>

->where('id', $arrayA)

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,821Questions: 1Answers: 10,127 Site admin

    Are you looking to do a WHERE ... IN ...? (I presume that id is not an array - or is it)?

    If so, then yes, it is quite possible. Have a read through the documentation available here which discusses how to perform complex where operations in Editor.

    Allan

  • alord84alord84 Posts: 24Questions: 15Answers: 1
    edited July 2015

    Yes and No, i didn't ask that question properly.
    What I wanted to do was to insert a variable in the condition after an IF statement, where my users_id is passed via the url. is there an easier way to do this?

    <?php                
    $powerusers=$row['id'];
    
    $allids="SELECT users_id2 FROM Table";
    
    if($users_id==$powerusers){$usersA=$allids;}
    else
    {$usersA="SELECT users_id2 FROM Table WHERE users_id2=$users_id";}
    
    ?>
    
    
    ->where( function ( $q ) {
        global $usersA;
        $q->where( 'Table.users_id2', '('.$usersA.')', 'IN', false );
    } )
    
  • allanallan Posts: 61,821Questions: 1Answers: 10,127 Site admin
    Answer ✓

    The only change I would suggest using the use statement rather than global (function ($q) use ($usersA) {. I don't see any other option at the moment.

    Allan

This discussion has been closed.