gpt4 book ai didi

mysql - where 子句中的列 'id' 在 codeigniter 中不明确

转载 作者:行者123 更新时间:2023-11-29 01:54:45 25 4
gpt4 key购买 nike

我想在 codeigniter 中连接两个表。我想根据登录用户显示数据。我这样做是为了获取用户的 session ID。它显示我在标题中提到的错误消息。当我评论“$this->db->where("id",$ this->session->userdata['logged_in']['id']);" 这部分可以正常工作。

模型

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();

控制者

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);
}

查看

<?php if($post) { ?> 
<?php foreach($post as $post){?>

<div><?php echo $post->firstname ; echo '&nbsp; &nbsp;'; echo $post->lastname;?></div> <br>
<div><?php echo $post->address ; echo '&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp;'?></div><br>
<div><?php echo $post->contact_no ; echo '&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp;'?></div> <br>
<div><?php echo $post->email ; echo '&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp;'?></div> <br>
<div><?php echo $post->location ; echo '&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp;'?></div> <br>

<?php }
} else {

?>
</div>
<div clospan="4" align="center">No records found to display</div>

最佳答案

列对于数据库不明确。尝试像这样更改 where 子句:

    $this->db->where("user.id",$this->session->userdata['logged_in']['id']);

$this->db->where("project.id",$this->session->userdata['logged_in']['id']);

如果是这样的话。由于两个表可能都有 id 列,因此您必须非常清楚您指的是哪一个。

关于mysql - where 子句中的列 'id' 在 codeigniter 中不明确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32271863/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com