We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14162
    • 67 Posts
    Is it possible to prepare a newquery on more than one table (tables that have no specific relationship but similar column titles)?

    e.g. Returning items from table1 AND table2 that have an id of 3.

    $a = $modx->newQuery({'table1','table2'});
    $a->where(array('id' => 3,));
    $results = $modx->getCollection({'table1','table2'},$a);
    etc...
    
      • 14162
      • 67 Posts
      Couldn't find an xPDO solution, but worked out a PDO solution instead:
      $stmt = $modx->query('
      SELECT *
      FROM table1 t1 
      WHERE t1.id = 3
      UNION ALL
      SELECT *
      FROM table2 t2
      WHERE t2.id = 3
      ');
      
      if ($stmt) { 
            while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
              $output .= $modx->getChunk($tpl,$row);
         }
      return $output;
      }