Search code examples
phpcodeigniterarray-merge

How can we use where condition in array_merge result in codeigniter


Here when I use my code like this am getting error Function name must be a string in,please have a look.

public function get_date_wise_agent_report($start_date,$end_date,$agent = NULL,$abc = NULL)
{
    $results1=$this->db->get('datas')->result();
    $results2=$this->db->get('abc_datas')->result();
    $data=array_merge($results1,$results2);
    $this->db->where_in('Date(date) >=',$start_date);
    $this->db->where_in('Date(date) <=', $end_date);

    return $data();
}

I had used array_merge to combine two results and from that I need to get get results between the two dates hope you can help me. Thanks.


Solution

  • Your code should be corrected as below.

    public function get_date_wise_agent_report($start_date, $end_date, $agent = NULL, $abc = NULL)
    {
    
        $this->db->where("DATE(date) BETWEEN '{$start_date}' AND '{$end_date}'")
        $query = $this->db->get('datas');
        $results1 = $query->result_array();
    
        $this->db->where("DATE(date) BETWEEN '{$start_date}' AND '{$end_date}'")
        $query = $this->db->get('abc_datas');
        $results2 = $query->result_array();
    
       //Here you need to use $query->result_array() instead of $query->result() because result() returns a object.
       //Go to following link to learn more about result
    
       //Here I assumed both `datas` and `abc_datas` tables are having `date` column.
    
        $data = array_merge($results1,$results2);
    
        return $data;
    }