CodeIgniter Active Record包含先前查询的列

时间:2012-07-05 22:40:57

标签: codeigniter codeigniter-2

我有一个需要运行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列甚至不在第二个查询中,但它包含在结果中。我该如何解决这个问题?谢谢。

1 个答案:

答案 0 :(得分:0)

尝试跑步:

$this->db->flush_cache()

之前

$this->db->select('id2')