数据不是从数据库中获取的
Data is not fetched from database
我正在尝试从其他人那里获取数据 table 但是当我加入 serviceplan table 时,查询结果为空,但是当我删除 serviceplan table 时,它完美地获取了数据。
这是我的模型的代码(没有服务计划 table-working)
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();
}
普通联接或内部联接仅获取 table 中共有的行。因此,在您的情况下,您的 serviceplan
table.
中没有匹配条件
验证一下。或者查看您的要求并尝试使用 leftjoin
而不是 join
.
另请看:Difference between joins
您可以使用 codeigniter 尝试这个简单的连接 table 查询,如下所示:
$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();
我正在尝试从其他人那里获取数据 table 但是当我加入 serviceplan table 时,查询结果为空,但是当我删除 serviceplan table 时,它完美地获取了数据。
这是我的模型的代码(没有服务计划 table-working)
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();
}
普通联接或内部联接仅获取 table 中共有的行。因此,在您的情况下,您的 serviceplan
table.
验证一下。或者查看您的要求并尝试使用 leftjoin
而不是 join
.
另请看:Difference between joins
您可以使用 codeigniter 尝试这个简单的连接 table 查询,如下所示:
$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();