0

Why this code doesn't work? Error call in foreach.

$notifications = $this->db->select('id, shopping_region_id')
        ->from('push_notifications')
        ->where('date<=NOW()')
        ->get()->result();

    foreach ($notifications as $notification)
    {
        $test = $this->db->select('user_id, shopping_region_id')
            ->from('user')
            ->where('shopping_region_id=',$notification->shopping_region_id)
            ->get()->result();

        print_r($test);

    }

PHP Fatal error: Call to a member function result() on boolean in

Shahzad Barkati
  • 2,532
  • 6
  • 25
  • 33
Alex Pavlov
  • 571
  • 1
  • 7
  • 24
  • Possible duplicate of [mysql\_fetch\_array() expects parameter 1 to be resource (or mysqli\_result), boolean given](http://stackoverflow.com/questions/2973202/mysql-fetch-array-expects-parameter-1-to-be-resource-or-mysqli-result-boole) – Matt in Washington Feb 16 '16 at 05:05
  • comment your `->where('date<=NOW()')` section and remove the `->result();` method, then `print_r($notifications)` your query, show me results that what you get ? – Qazi Feb 16 '16 at 05:05
  • $notifications variable give you proper result or not – Aslam Patel Feb 16 '16 at 05:06
  • Yes, $notifications gives me a proper result. – Alex Pavlov Feb 16 '16 at 05:12
  • @Frazelli can you show me the notifications result array ? – Qazi Feb 16 '16 at 05:16
  • @Qazi [0] => stdClass Object ( [id] => 2 [shopping_region_id] => 38 ) [1] => stdClass Object ( [id] => 4 [shopping_region_id] => 38 ) [2] => stdClass Object ( [id] => 5 [shopping_region_id] => 38 ) [3] => stdClass Object ( [id] => 6 [shopping_region_id] => 38 ) – Alex Pavlov Feb 16 '16 at 05:17
  • also tell me. when you get above proper result? after commenting the where clause ? or with where clause ? – Qazi Feb 16 '16 at 05:18
  • @Qazi with where clause. I didn't comment anyting, because the first query works fine. – Alex Pavlov Feb 16 '16 at 05:21
  • ->where('shopping_region_id',$notification->shopping_region_id) in foreach – Praveen Kumar Feb 16 '16 at 05:24
  • @Frazelli on which `result()` you are getting error, 1st one or 2nd one which is inside the loop? – Qazi Feb 16 '16 at 05:28

1 Answers1

1

Try this

foreach ($notifications as $notification)
    {
        $test = $this->db->select('user_id, shopping_region_id')
            ->from('user')
            ->where('shopping_region_id' , $notification->shopping_region_id)
            ->get()->result();

        print_r($test);

    }
Praveen Kumar
  • 2,408
  • 1
  • 12
  • 20