代码之家  ›  专栏  ›  技术社区  ›  Sagar Parikh

未从数据库中提取数据

  •  0
  • Sagar Parikh  · 技术社区  · 6 年前

    我试图从其他表中获取数据,但当我加入ServicePlan表时,查询结果为空,但当我删除ServicePlan表时,它的提取数据是完全正确的。

    这是我的模型代码(不使用serviceplan表)

    public function send_mail() {
        // $user_id=$this->session->userdata('user_id');
    
        $query=$this->db->select('*, employee.name_emp as emp_name, customer.name as cust_name, servicetype.name_set as s_name',
            'serviceplan.price as p_rice')->from('appointment')
            // ->where('id_app',$appointment_id)
            ->join('customer', 'customer.id= appointment.name_app')
            ->join('servicetype', 'servicetype.id_set= appointment.sertype')
            ->join('employee', 'employee.id_emp= appointment.emp')
            // ->join('serviceplan', 'serviceplan.id_sep= appointment.price_app')
            ->get();
    
        echo $this->db->last_query();
        exit();        
        return $query->result();
    }
    
    2 回复  |  直到 6 年前
        1
  •  0
  •   Rahul Patel    6 年前

    普通联接或内部联接只获取两个表中的公用行。因此,在您的情况下,您的 serviceplan 表。

    验证一下。或者看看你的需求然后尝试使用 leftjoin 而不是 join .

    另请看: Difference between joins

        2
  •  0
  •   AStopher    6 年前

    您可以使用下面的代码点火器尝试这个简单的联接表查询:

    $email='myEmail@test.com';
    $this->db->select('*');
    $this->db->from('table1');
    $this->db->where('table1.email',$email);
    $this->db->join('table2', 'table1.email = table2.email');
    $query = $this->db->get();
    $assignedData=$query->result_array();