【发布时间】:2018-05-25 17:30:42
【问题描述】:
我在视图顶部收到此错误(即使视图按预期正确加载数据)
遇到了 PHP 错误
严重性:警告消息:非法偏移类型文件名: 数据库/DB_query_builder.php 回溯:
文件: C:\wamp64\www\procurement_v_alpha1\application\models\Notifications.php 行:32 功能:哪里
我的模型看起来像,
public function user_alert ()
{
$session_data = $this->session->userdata['logged_in'];
$role = $session_data['role'];
$dept = $session_data['dept'];
$data_user = array(
'role' => $role,
'dept' => $dept
);
$role = $data_user['role'];
$this->db->from('notification');
$this->db->select('pr_id,item_name,dept_division');
$this->db->where($role, 0);
$query = $this->db->get();
return $query -> result_array();
}
你们能帮我解决这个问题吗? 使用 'where' 方法有什么问题吗?
【问题讨论】:
-
应该是
role而不是$role -
是的,但它是一个变量,它会根据用户而变化。所以我需要选择该列的每个“角色”都有一个列。在没有会话数据之前它工作得很好。但现在我收到了这个错误
-
但我认为它的字段名称应该对每个用户都相同,
$role应该有价值。所以应该是('role',$role)。有关更多详细信息,您可以添加您的表结构吗? -
试试
$this->db->where('role', '0');如果不行试试$this->db->where('role', $role);
标签: php mysql codeigniter offset