phpmysqlmysql-error-1054on-clause

Error Number: 1054 Unknown column '2021-08-23' in 'on clause'


I have join many tables in this query via LEFT JOIN and i want to apply condition on table but php is giving me following error

Error Number: 1054 Unknown column '2021-08-23' in 'on clause'

SELECT i.isn_Add_Date, s.scentre_Name, i.isn_Job_No,cp.cpart_Part_Id, cp.cpart_Part,cp.cpart_Qty,cp.cpart_Rate,cp.cpart_Amount, p.product_Name,m.model_Name,c.complaint_Job_No,c.complaint_Add_Date, c.complaint_Under_Warranty,cp.cpart_Qty,cp.cpart_Rate,cp.cpart_Amount FROM complaints as c LEFT JOIN complaint_parts as cp ON c.complaint_Id = cp.cpart_Complaint_Id LEFT JOIN scentres as s ON s.scentre_Id = c.complaint_Scentre_Id LEFT JOIN products as p ON p.product_Id = c.complaint_Product_Id LEFT JOIN models as m ON m.model_Id = c.complaint_Model_Id LEFT JOIN isn as i ON i.isn_Complain_Number = c.complaint_Job_No AND i.isn_Add_Date BETWEEN '2021-08-23' AND '2021-08-26' WHERE c.complaint_Scentre_Id = '1' AND c.complaint_Status = 'Delivered' AND c.complaint_Trash = 0

here is my php code

$this->db->select('i.isn_Add_Date,s.scentre_Name,i.isn_Job_No,cp.cpart_Part_Id,cp.cpart_Part,cp.cpart_Qty,cp.cpart_Rate,cp.cpart_Amount,p.product_Name,m.model_Name,c.complaint_Job_No,c.complaint_Add_Date,c.complaint_Under_Warranty,cp.cpart_Qty,cp.cpart_Rate,cp.cpart_Amount');
            
            $this->db->join('complaint_parts as cp', 'c.complaint_Id = cp.cpart_Complaint_Id ', 'left');
            
            $this->db->join('scentres as s', 's.scentre_Id = c.complaint_Scentre_Id', 'left');
            $this->db->join('products as p', 'p.product_Id = c.complaint_Product_Id', 'left');
            $this->db->join('models as m', 'm.model_Id = c.complaint_Model_Id', 'left');

            $this->db->JOIN('isn as i', 'i.isn_Complain_Number = c.complaint_Job_No AND i.isn_Add_Date BETWEEN '.str_replace('/', '-', $fromDate).' AND '.str_replace('/', '-', $toDate).'', 'LEFT'); 
            
            
            
            $this->db->where("c.complaint_Scentre_Id", $serviceCenterId[0]);
            $this->db->where("c.complaint_Status",'Delivered');
            $this->db->where("c.complaint_Trash", 0);
            
            $query = $this->db->get("complaints as c");

Solution

  • change

     `2021-08-23` AND `2021-08-26`
    

    to

    '2021-08-23' AND '2021-08-26'
    

    as the ` character implies columns and not strings