Try to search your question here, if you can't find : Ask Any Question Now ?

Cannot join 3 table in Codeigniter

HomeCategory: stackoverflowCannot join 3 table in Codeigniter
Avatarkundan asked 5 months ago

I am retrieving products from codeigniter there are three tables:

  1. dg_products
  2. dg_rating
  3. dg_like

after joining dg_products and dg_rating is working but i want to get the like status from dg_like.
structure of dg_like is:

id | P_id | Uid

from session i am able to retrieve current logged in user id but cannot retieve whether that user has liked that particular product or not. Please give any suggestions.

public function get_featured()
    {
        $this->db->select('dg_products.*, AVG(dg_rating.rating) As averageRating');
        $this->db->from('dg_products');
        $this->db->join('dg_rating', 'dg_products.id = dg_rating.product_id','left');
        $user_info=$this->session->userdata('logged_in');
        $user_id=$user_info['id'];
        if($user_id!='') {
        $this->db->join('dg_like', 'user_id = dg_like.u_id');
        }
        $this->db->where('dg_products.is_featured_prod','1');
        $this->db->group_by("dg_products.id");
        $query = $this->db->get();   
        $result = $query->result();
        return $result; 
    }
1 Answers
Best Answer
Avatarnaveen answered 5 months ago
Your Answer

17 + 2 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com