function getInstancesData($params, $logic = 'OR', $order) { $res = parent::getInstancesData($params, $logic, $order); // Get the comments to go with them if (!empty($res)) { $sql = 'SELECT c.noteid, c.*, p.first_name as creator_fn, p.last_name as creator_ln FROM note_comment c JOIN person p on c.creator = p.id WHERE noteid IN (' . implode(', ', array_keys($res)) . ') ORDER BY noteid, created'; $db =& $GLOBALS['db']; $comments = $db->queryAll($sql, null, null, true, false, true); check_db_result($comments); foreach ($res as $i => $v) { $res[$i]['comments'] = array_get($comments, $i, array()); } } return $res; }