-1

I'm trying to take some values form the database and I tried the code like this

    $condition = ['restaurant_id' => $restaurant_id, 'menu_category_id' => $menu_category_id, 'current_template_id' => '0'];
    $this->db->select('time_range');
    $this->db->from('menu_category_timing_t');
    $this->db->where($condition);
    $query = $this->db->get();
    $data = $query->result();

    if ( $data ) {
        print_r("data available")
    }
    else {
        print_r("data is not available");
    }

But it showing some error as Call to a member function result() on a non-object

Midhun
  • 115
  • 1
  • 1
  • 10
  • 1
    Possible duplicate of [Reference - What does this error mean in PHP?](http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) – Marcin Orlowski Apr 24 '17 at 08:43
  • Possible duplicate of [Call to member function result() of non object codeigniter](http://stackoverflow.com/questions/22685990/call-to-member-function-result-of-non-object-codeigniter) – Masivuye Cokile Apr 24 '17 at 08:47

1 Answers1

0

Instead of using $data = $query->result(); use $data = $query->result_array();

Incase if their is no value for the query, it will return an empty array. So now your if else condition will work.

Mani Kandan
  • 699
  • 1
  • 10
  • 30