我想使用会话ID过滤数据。有一张如下表。
id | user_id | plan
1 | 1 |.sjhsjh.jpg
2 | 2 |bchdj.jpg
我想根据登录user.user id过滤该数据库值,这是用户表的外键。我之前已经过滤了它,但现在它无法正常工作。
模型
function get_plan(){
$this->db->select("floor_plan.id,floor_plan.image");
$this->db->where("user_id",$this->session->userdata['logged_in']['id']);
$this->db->from('floor_plan');
$query = $this->db->get();
return $query->result();
会话
<?php
if (isset($this->session->userdata['logged_in'])) {
$firstname = ($this->session->userdata['logged_in']['firstname']);
$email = ($this->session->userdata['logged_in']['email']);
$id = ($this->session->userdata['logged_in']['id']);
} else {
header("location: login");
}
答案 0 :(得分:0)
更改模型如下。
function get_plan(){
$userdata=$this->session->userdata('logged_in');
$this->db->select("floor_plan.id,floor_plan.image");
$this->db->where("user_id",$userdata['id']);
$this->db->from('floor_plan');
$query = $this->db->get();
return $query->result();
}
会话更改如下。
<?php
if (isset($this->session->userdata('logged_in'))) {
$userdata=$this->session->userdata('logged_in');
$firstname = $userdata['firstname'];
$email = $userdata['email'];
$id = $userdata['id'];
} else {
redirect("login/index");
}