我的模型中有以下代码。我正在加载报价详细信息页面,它给了我错误
Severity: Notice
Message: Undefined index: viewc
Filename: statistics/Statistic_model.php
Line Number: 551
Statistic_model:
public function getTotalDetailsViewOfActiveOffer($comid) {
$this->db->select('count(statistic_offer_view_count.id) as viewc');
$this->db->from('statistic_offer_view_count');
$this->db->join('offers', 'offers.id = statistic_offer_view_count.offer_id');
$this->db->where('offers.com_id',$comid);
$this->db->where('offers.approved_status',"2");
$this->db->where('offers.enddate >=',date('Y-m-d'));
$this->db->group_by("offers.com_id");
$query = $this->db->get();
$row = $query->result_array();
$count=$row['viewc']; //this is line 551
}
知道如何解决此错误吗?
该错误意味着索引viewc
不在数组中$query->result_array()
很可能是因为查询失败或返回 null。你应该养成做以下事情的习惯:
$query = $this->db->get();
if ($query->num_rows() > 0) {
return $query->row()->viewc;
}
return false; // or in this case 0 or whatever
在你的代码中,你从数据库中选择数据 多个数组。并像单个数组一样将 at 分配给变量。 你的代码....
$row = $query->result_array();
$count=$row['viewc'];
正确的方法是在你的传导中分配一个变量是....
$data = array();
foreah($row as $key => $value){
$data[$key] = $value['viewc'];
}