0

I am trying to get data from others table but when I join serviceplan table the result of query is empty but when I remove serviceplan table its fetched data perfectly.

Here is the code of my Model(without serviceplan 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();
}
Sagar Parikh
  • 288
  • 5
  • 20

2 Answers2

0

Normal joins or Inner Join only gets the rows common in both the tables. So, in your case, there are not matching conditions in your serviceplan table.

Verify it. Or look upon your requirements and try using leftjoin instead of join.

Also look: Difference between joins

Rahul Patel
  • 639
  • 6
  • 12
0

You may try this simple join table query using codeigniter as below:

$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();
AStopher
  • 4,207
  • 11
  • 50
  • 75
Rudra
  • 535
  • 4
  • 16