我想结合这两个查询但我收到错误
在数组错误
上调用成员函数num_rows()
我不确定我做错了什么。我希望有人能看到我是否正确完成了查询。
我有这些表格:
PersonTransactions表通过ID链接其他3个表 成人和儿童表共享相似的字段,但不完全是我分开它们的原因。
以下查询代码:
$this->db->limit($limit,$start);
$this->db->select('cn.firstname AS Firstname, cn.lastname AS Lastname,t.id AS id,pt.personType AS PersonType,p.name AS ProductName,t.adults AS Adults,t.children AS Children,t.total AS Total,t.country as Country,t.transactionDate as TransactionDate');
$this->db->from('PersonTransactions AS pt');
$this->db->join('Products as p','pt.productID = p.id','LEFT');
$this->db->join('Transactions as t','pt.transactionID = t.id AND pt.personType="child"','LEFT');
$this->db->join('Children as cn','cn.id = pt.personID AND cn.personType=pt.personType','LEFT');
$query1 = $this->db->get_compiled_select();
$this->db->select('pn.firstname AS Firstname, pn.lastname AS Lastname,t.id AS id,pt.personType AS PersonType,p.name AS ProductName,t.adults AS Adults,t.children AS Children,t.total AS Total,t.country as Country,t.transactionDate as TransactionDate');
$this->db->from('PersonTransactions AS pt');
$this->db->join('Products as p','pt.productID = p.id','LEFT');
$this->db->join('Transactions as t','pt.transactionID = t.id AND pt.personType="adult"','LEFT');
$this->db->join('Person as pn','pn.id = pt.personID AND pt.personType=pt.personType','LEFT');
$query2 = $this->db->get_compiled_select();
$query = $this->db->query($query1." UNION".$query2);