CodeIgniter - return only one row? CodeIgniter - return only one row? database database

CodeIgniter - return only one row?


You've just answered your own question :)You can do something like this:

$query = $this->db->get();$ret = $query->row();return $ret->campaign_id;

You can read more about it here: http://www.codeigniter.com/user_guide/database/results.html


This is better way as it gives you result in a single line:

$this->db->query("Your query")->row()->campaign_id;


To add on to what Alisson said you could check to see if a row is returned.

// Query stuff ...$query = $this->db->get();if ($query->num_rows() > 0){    $row = $query->row();     return $row->campaign_id;}return null; // or whatever value you want to return for no rows found