我是codeigniter的初学者,我的查询有问题,我想从一个表中检索所有数据,我将使用另一个表的数据。例如,我有一个orderlogs表,我想要检索orderlogs表的所有数据,它将与登录的用户名相匹配。所以我想要具体做的是每个用户都可以专门查看他们所做的转换历史。我正在预订系统。这是我的型号代码:
ITEM MODEL查询:
public function getUserslog($username){
$this->db->select('*');
$this->db->from('orderlogs');
$this->db->join('users','users.username=orderlogs.username');
$this->db->where('orderlogs.username',$username);
$q = $this->db->get();
return $q->result();
}
控制器代码:
public function itemuserlogs() {
$check_session = $this->session->userdata('login');
if (!isset($check_session)) {
redirect('login/index','refresh');
}
$this->pagi_orders();
$username = $this->session->userdata('username');
$user['user'] = $this->UserModel->userdata($username);
$this->load->view('layout/header_user', $user);
$this->load->model('ItemModel');
$data['items'] = $this->ItemModel->getUserslog(5, $this->uri->segment(3));
$data['page'] = $this->uri->segment(3);
$msg = $this->session->userdata('msg');
if (isset($msg)) {
$data['msg'] = $msg;
}
$item_id = $this->session->userdata('item_id');
if (isset($item_id)) {
$this->session->unset_userdata('item_id');
}
$this->load->view('item/item_logs_view', $data);
}
希望你能帮助谢谢。
答案 0 :(得分:1)
检查您的代码。我认为您应该为您的Model方法提供用户名
更改
$this->ItemModel->getUserslog(5, $this->uri->segment(3));
要
$this->ItemModel->getUserslog($username);
答案 1 :(得分:0)
更改
$ this-> ItemModel-> getUserslog(5,$ this-> uri-> segment(3));
要
$这 - > ItemModel-> getUserslog($用户名);