php - codeigniter中的内部连接查询
问题描述
代码:
public function draft_post($idd)
{
$this->db->select('*');
$this->db->from('registration');
$this->db->join('draft_registration', 'registration.user_id= draft_registration.user_id','INNER');
$this->db->where('registration.user_id', $idd);
$query = $this->db->get();
$result = $query->result_array();
return $result;
}
在这段代码中,我有两个表,即registration and draft_registration
. 现在,我在这里做什么,我想在 Codeigniter 中运行内部连接。现在,当我点击这个查询时会发生phpmyadmin
什么显示错误的数据,即我有两行draft_registration
和一行在registration
表中,但它总是显示两个错误的表,我的查询看起来像我打印时的样子,如下所述:
SELECT *
FROM `registration`
INNER JOIN `draft_registration` ON `registration`.`user_id`= `draft_registration`.`user_id`
WHERE `registration`.`user_id` = '20181121064044'
那么,我该如何解决这个问题呢?请帮我。
谢谢你
解决方案
使用下面的代码
public function draft_post($idd)
{
$this->db->select('registration.*,draft_registration.*');
$this->db->from('registration');
$this->db->join('draft_registration', 'registration.user_id= draft_registration.user_id');
$this->db->where('registration.user_id', $idd);
$query = $this->db->get();
$result = $query->result_array();
return $result;
}
或者您可以与对象一起使用
public function draft_post($idd)
{
$this->db->select('a.*,b.*');
$this->db->from('registration a');
$this->db->join('draft_registration b', 'a.user_id= b.user_id');
$this->db->where('a.user_id', $idd);
$query = $this->db->get();
$result = $query->result_array();
return $result;
}
推荐阅读
- python - Python从内部类访问外部类的自我
- python - Python:在 numpy 数组上进行矢量化
- powershell - Powershell Get ADGroupMember 有 2 个身份组
- javascript - 开玩笑测试只返回对象内的字符串
- java - 在边框窗格布局中居中 VBox
- javascript - 在 React 中使用 useState 在功能组件中未更新状态
- github - 是否可以仅登录一个组织
- javascript - Material React Select Multiple:单击选定元素时如何从数组中删除?
- css - 变亮/变暗 scss 函数中的自定义 css 属性
- python - 如何在调试模式下更新 Visual Studio Code 使用的 ptvsd