I have a function in my model for selecting items from a database and returning it as an array. My question is, how can I manually create the array, so that I can for example, change the date format?
Here is what I have:
$sql = 'SELECT * FROM prayer_requests ORDER BY id DESC';
$query = $this->db->query($sql);
if($query->num_rows() > 0) return $query->result();
else return FALSE;
I’m guessing I would need some kind of loop? I know it must be simple, but can’t figure out exactly how to do it.
If you want to get the result as an array, you can use
result_array()instead ofresult().You can read more about generating results with CodeIgniter here: http://codeigniter.com/user_guide/database/results.html
Ex:
EDIT:
If you want to modify the data before putting it into the array. You’ll need a loop, and while in the loop, use any functions necessary to change the data you want. Then assign it back the loop variable, and append it to an array (which has already been initialized before the loop).