[英]Codeigniter $query->result() returns strange results
This peace of code is driving me crazy for last hour... I have this model which should return all non active records from DB 如此宁静的代码使我在最后一个小时内发疯……我有这个模型,应该从数据库返回所有非活动记录
$query = $this->db->get($tableName);
echo $this->db->last_query();
var_dump($query->result());
$this->db->last_query()
output is $this->db->last_query()
输出为
SELECT * FROM `locations` LEFT JOIN `provinces` ON `provinces`.`id_province` = `locations`.`id_province` LEFT JOIN `countries` ON `countries`.`id_country` = `provinces`.`id_country` LEFT JOIN `statuses` ON `statuses`.`id_status` = `locations`.`id_status` WHERE `locations`.`active` = '0' ORDER BY `locations`.`id_location` DESC LIMIT 50
If i run exactsame query in phpmyadmin i get correct results 如果我在phpmyadmin中运行完全相同的查询,则会得到正确的结果
But when i var_dump data var_dump($query->result());
但是当我var_dump data var_dump($query->result());
i get the following results 我得到以下结果
array (size=50)
0 =>
object(stdClass)[61]
public 'unique_id' => string 'OWYwYjBmNm' (length=10)
public 'active' => string '1' (length=1)
public 'owner_name' => string 'Cleve Greenfelder' (length=17)
1 =>
object(stdClass)[62]
public 'unique_id' => string 'YWY4YmMzMm' (length=10)
public 'active' => string '1' (length=1)
public 'owner_name' => string 'Bradford Hyatt' (length=14)
Why/how this active state get's overwritten from 0 to 1? 为什么/如何将此活动状态从0覆盖为1? IF you need any additional information's, please let me know and i will provide. 如果您需要任何其他信息,请告诉我,我会提供。 Thank you! 谢谢!
Once i wrote a question, answer quickly appeared in my head :) Table Countries has also active field, so this field overwrites active state as enabled. 一旦我写了一个问题,答案很快就出现在我的脑海:)表国家/地区也有活动字段,因此该字段会覆盖已启用的活动状态。 I needed to specified fields and there's name in query in order to get proper results 我需要指定字段,并且在查询中有名称才能获得正确的结果
$fields = 'unique_id, locations.active as active, ....';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.