由于某些原因,在Codeigniter中,我的SQL查询基于行数返回对象数组的重复复制。奇怪的是,如果我将我的SQL查询直接放入phpMyAdmin,它会返回正确的结果 - 我应该补充说,代码几乎与我正常工作的另一个调用函数相同。
在我盯着我的代码这么长时间后,我只是失明了吗?!
更新: 只是附注,我没有包含我的代码来操纵$ query,因为我的SQL结果已经错了。
结果
CI_DB_mysqli_result Object
(
[conn_id] => mysqli Object
(
// Information
(
)
//Information
)
[result_id] => mysqli_result Object
(
[current_field] => 0
[field_count] => 4
[lengths] =>
[num_rows] => 2
[type] => 0
)
[result_array] => Array
(
)
[result_object] => Array
(
[0] => stdClass Object
(
[id] => 1594
[user_id] => 102
)
[1] => stdClass Object
(
[id] => 1279
[user_id] => 102
)
)
[custom_result_object] => Array
(
)
[current_row] => 0
[num_rows] =>
[row_data] =>
)
1
CI_DB_mysqli_result Object
(
[conn_id] => mysqli Object
(
// Information
(
)
//Information
)
[result_id] => mysqli_result Object
(
[current_field] => 0
[field_count] => 4
[lengths] =>
[num_rows] => 2
[type] => 0
)
[result_array] => Array
(
)
[result_object] => Array
(
[0] => stdClass Object
(
[id] => 1594
[user_id] => 102
)
[1] => stdClass Object
(
[id] => 1279
[user_id] => 102
)
)
[custom_result_object] => Array
(
)
[current_row] => 0
[num_rows] =>
[row_data] =>
)
1
代码
function data($update_id) {
$query = $this->db->query('
SELECT *
FROM `list`
JOIN `tasks` ON list.id = tasks.list_id
WHERE (tasks.date < \' 2016-03-19 \' AND tasks.list_id = '$update_id')
ORDER BY `tasks`.`date` DESC
');
return $query;
}
我得到了上面的结果。我的代码中甚至没有循环,所以我不明白循环的来源......
感谢您的协助。
答案 0 :(得分:0)
使用return $ query-&gt; result();而不是返回$ query