我有一个需要运行2个查询的函数。第一个查询运行正常。第二个不是因为它包含来自上一个查询的列,而不是来自同一个表 第一个查询:
function1($id) {
$sql = "SELECT id FROM table1 WHERE id2 = $id";
return($this->db->query($sql));
}
第二个问题:
function2() {
$this->db->select('id2');
$this->db->from('table2');
$this->db->where('col1', '1');
$this->db->limit($random_number, 1);
return($this->db->get());
}
调用函数:
function() {
$rs1 = function($id)->result_array(); // runs ok.
$rs2 = function2()->result_array(); // error.
}
错误消息:
A Database Error Occurred
Error Number: 1054
Unknown column 'id' in 'field list'
SELECT `id`, `id2` FROM (`table2`) WHERE `col1` = '1' LIMIT 1, 30
第id
列甚至不在第二个查询中,但它包含在结果中。我该如何解决这个问题?谢谢。
答案 0 :(得分:0)
尝试跑步:
在$this->db->flush_cache()
之前 $this->db->select('id2')