db->table('payment_status')->select('payment_status.*,CONCAT(COALESCE(customers.first_name, ""), " ", COALESCE(customers.last_name, "")) AS customer_name,books.short_code as scheme_name') ->join('customers','customers.customer_id = payment_status.customer_id and customers.isactive = 1') ->join('books','books.book_id = payment_status.scheme_id and books.isactive = 1'); if (!empty($fromDate) && !empty($toDate)) { $builder->where('payment_status.created_at >=', $fromDate.' 00:00:00') ->where('payment_status.created_at <=', $toDate. ' 23:59:59'); } if ($status == 1) { $builder->where('payment_status.status >', 0); // Correct usage of where() for status }else{ $builder->where('payment_status.status', null); } $builder->where('payment_status.is_active',1); $builder->orderBy('payment_status.created_at','desc'); $data = $builder->get()->getResultArray(); // log_message('error',json_encode($this->db->getLastQuery()->getQuery())); return $data; // Fetch and return as an array } }