I've got a method that's meant to return a single value. Because ->result() returns an array I'm using the following to return the single value I'd like to get:
return array_pop($this->db->query($SQL)->result())->event_name;
while it works perfectly fine, I'm wondering if there's something built into CI that maybe I've missed in the documentation. I also use this same trick to return a single record:
return array_pop($this->db->query($SQL)->result());
Is there a better way to do this?
row_array() will return you the 1st row found as an array, and row() will return it as an object.
So instead of array_pop, you can use:
return $this->db->query($SQL)->row()->event_name;
OR
return $this->db->query($SQL)->row_array();
https://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