Liam Fell
Liam Fell

Reputation: 1320

Issue returning single row from active record query

I have the following query, in Code Igniter active records:

    $this->db->select('overflow');
    $query = $this->db->get_where('raffles', array('lottery_id' => $lottery_id));
    var_dump($query->first_row()->overflow);
    exit;

However, I get the following error when attempting var_dump the singe row:

Trying to get property of non-object

This does look like valid code to me however, can anyone spot the issue?

Upvotes: 2

Views: 59

Answers (1)

Abdulla Nilam
Abdulla Nilam

Reputation: 38642

Try this

$this->db->select(*);
$query = $this->db->get_where('raffles', array('lottery_id' => $lottery_id));
$row = $query->first_row('array'); # Changed
print_r($row); # Added

By default they return an object unless you put the word "array" in the parameter

Upvotes: 1

Related Questions