We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24676
    • 60 Posts
    I don't know if I am being stupid here but I am having problems creating a where query where i am passing multiple ids.

    I am basically trying to do the following taken from the docs.

    $query = $xpdo->newQuery('Box');
    $query->where(array(
        array( 
            'ProductsFunction.product' => 14
        ),
        array(
            'ProductsFunction.product' => 1
        )
    ),xPDOQuery::SQL_OR);
    



    However the nested array I am trying to pass is being created dynamically and so I output a string assigned to a variable that looks like the following.

    array( 'ProductsFunction.product' => 14),array( 'ProductsFunction.product' => 1),array( 'ProductsFunction.product' => 15),array( 'ProductsFunction.product' => 16),array( 'ProductsFunction.product' => 17),array( 'ProductsFunction.product' => 18),array( 'ProductsFunction.product' => 19)),xPDOQuery::SQL_OR1


    How do I pass this string as a variable into my where statement?

    $query->where(array(.....


    I know my query works when I hard code it in (as in the above example)

    Hope that makes sense.

    This question has been answered by opengeek. See the first response.

    • discuss.answer
      • 22303 MODX Staff
      • 10,725 Posts
      If you just have an array of the id's, why not use IN rather than all those ORs?

      $query = $xpdo->newQuery('Box', array( 
          'ProductsFunction.product:IN' => $arrayOfProductIds
      ));
      
        • 24676
        • 60 Posts
        Ok - I think I probably need to explain a bit more clearly what I am trying to do. My original post was pretty confusing.

        Ultimately I am trying execute a query based on a list of IDs I pass in my WHERE statement. My query looks like this.

        $query = $modx->newQuery('FunctionInfo');
        $query->innerJoin('ProductFunction','ProductsFunction', 'ProductsFunction.function = FunctionInfo.id');
        
        $query->where(array(array( 'ProductsFunction.product' => 14),array( 'ProductsFunction.product' => 1),array( 'ProductsFunction.product' => 15),array( 'ProductsFunction.product' => 16),array( 'ProductsFunction.product' => 17)),xPDOQuery::SQL_OR); 
        


        That works fine when I hard code it. The problem is I have the IDs in an array. How do I pass these ids into my query?
          • 24676
          • 60 Posts
          Thanks opengeek!!!

          I was being stupid.....!!!!!!!