dptdb84606 2019-01-11 10:56 采纳率: 0%
浏览 68

当其中一个表中没有记录时,不显示记录

I am using Join query to get data from multiple table which is working.

Now my issue is, when there is no records in one of the table(tbl_Fees or membership_details) then I am not getting the records. Some time I am getting error. It should be display atleast my members records.

I tried below code

Model

public function Memberinfo(){
   $getDetails = array('members.member_id'=>$this->session->userdata['login_session']['id'],'members.is_status'=>1);
   $result = $this->db->where($getDetails)
                      ->select('*')
                      ->from('members')
                      ->join('membership_details', 'members.member_id = membership_details.member_id','LEFT')
                      ->join('tbl_Fees', 'membership_details.Fees_id = tbl_Fees.Fees_id')
                      ->get()
                      ->row();
                return $result;

        } 

Would you help me out in this?

  • 写回答

1条回答 默认 最新

  • doumi9661 2019-01-11 12:44
    关注

    As a commenter pointed out, this is because of the join you have specified. Using JOIN will default to an inner join - hence why you are not getting your desired result.

    Here are the different types of the JOINs available in SQL:

    (INNER) JOIN: Returns records that have matching values in both tables

    LEFT (OUTER) JOIN: Return all records from the left table, and the matched records from the right table

    RIGHT (OUTER) JOIN: Return all records from the right table, and the matched records from the left table

    FULL (OUTER) JOIN: Return all records when there is a match in either left or right table

    For reference, please see the images below which should help you visualize the joins more easily.

    Example of INNER JOIN Example of LEFT JOIN Example of RIGHT JOIN

    And finally, the join you are probably looking for:

    Example of INNER JOIN

    This should be enough information for you to correct your code.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题