At the moment if I am doing a query on the database that should only return one row, using:
...query stuff... $query = $this->db->get(); $ret = $query->result(); return $ret[0]->campaign_id;
Is there a CodeIgniter function to return the first row? something like $query->row();
Or even better would be the ability to, if there was only one row, to just use the query object directly.
e.g. $query->campaign_id;
$query = $this->db->get(); $ret = $query->result(); return $ret[0]->campaign_id; Is there a CodeIgniter function to return the first row? something like $query->row(); Or even better would be the ability to, if there was only one row, to just use the query object directly.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With