CodeIgniter填充表格输入表格数据

时间:2013-07-06 03:03:57

标签: php codeigniter model

我可以通过将result()更改为result_array()来消除第29行错误。但是preg_match()字符串问题仍然存在。

型号:

function get_room_details($data_room_type = array() ) {
    $query = $this->db->query('SELECT rt_id, rt_name FROM room_type ORDER BY rt_name ASC');
    $this->db->query($query);

    if($query->num_rows()>0) {
        foreach($query->result() as $row) {
            $data_room_type[$row['rt_id']] = $row['rt_name'];
        }
    }
    return $data_room_type;
    echo "<pre>";
    print_r($data_room_type);
    echo "</pre>";
}

错误:

enter image description here

1 个答案:

答案 0 :(得分:2)

删除此行,它是多余的并导致错误:

 $this->db->query($query);

您已经创建了结果对象(此var包含结果,它不是查询字符串):$query = $this->db->query('SELECT rt_id, rt_name FROM room_type ORDER BY rt_name ASC');,然后将其作为参数传递给查询方法 - 它会导致错误。

相关问题