[英]Column 'id' in where clause is ambiguous in codeigniter
I want to join two tables in codeigniter. 我想在codeigniter中加入两个表。 I want to display data according to login user.I do it getting session id of user.it display error message which I mention on heading.when i comment "
$this->db->where("id",$this->session->userdata['logged_in']['id']);"
我想根据登录用户显示数据。我获取用户的会话ID。它显示我在标题中提到的错误消息。当我评论“
$this->db->where("id",$this->session->userdata['logged_in']['id']);"
this part it will work fine. 这部分将正常工作。
model 模型
function get_user(){
$this->db->select("user.firstname,user.lastname,user.address, user.email, user.contact_no, project.location");
$this->db->where("id",$this->session->userdata['logged_in']['id']); //check login user
$this->db->from('user');
$this->db->join('project', 'project.client_id = user.id');
$query = $this->db->get();
return $query->result();
controller 调节器
public function index(){
$data['post'] = $this->profile_model->get_user(); // calling Post model method getPosts()
$this->load->view('user_include/header');
$this->load->view('user_site/profile',$data);
}
view 视图
<?php if($post) { ?>
<?php foreach($post as $post){?>
<div><?php echo $post->firstname ; echo ' '; echo $post->lastname;?></div> <br>
<div><?php echo $post->address ; echo ' '?></div><br>
<div><?php echo $post->contact_no ; echo ' '?></div> <br>
<div><?php echo $post->email ; echo ' '?></div> <br>
<div><?php echo $post->location ; echo ' '?></div> <br>
<?php }
} else {
?>
</div>
<div clospan="4" align="center">No records found to display</div>
Column is ambiguous for database. 列对于数据库是不明确的。 Try changing the
where
clause like this: 尝试像这样更改
where
子句:
$this->db->where("user.id",$this->session->userdata['logged_in']['id']);
or 要么
$this->db->where("project.id",$this->session->userdata['logged_in']['id']);
if that's the case. 如果是这样的话。 Since both tables may have an
id
column, you must be very clear which one you refer to. 由于两个表都可能有一个
id
列,因此您必须非常清楚地引用哪个表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.