I need to use if statement in join query in Codeigniter. I try this query...
$partners = $this->db->select("h.partner_id,hd.id as detail_id,v.*, hd.handshake_id ,sum(if(hd.result = '0',1, 0)) AS not_tested ,sum(if(hd.result = '1',1, 0)) AS positive,sum(if(hd.result = '2',1, 0)) AS negative", FALSE)
->from("handshake h")
->join("visitor v", 'IF(h.visitor_id = "'.$visitor_data['id'].'", h.partner_id = v.id , h.visitor_id = v.id ) ', 'left',FALSE)
->join("handshake_detail hd", ' hd.handshake_id = h.id AND hd.visitor_id <> "'.$visitor_data["id"].'"', 'left',FALSE)
->where("h.visitor_id", $visitor_data['id'])
->or_where("h.partner_id", $visitor_data['id'])
->group_by("h.partner_id")
->get()->result_array();
if we write above query in MySQL so, it work but when I try in Codeigniter syntax so it generate error like this...
FUNCTION trustcrowd_1.0.IF does not exist. Check the 'Function Name Parsing and Resolution' section in the Reference Manual
so please help to find out right syntax of Codeigniter query.
my working query is...