My model returns data as mysql objects:
return $q->result();
Now, I want to shuffle/randomize the data and send it to the view file. But when I use the shuffle($data) on the object, it doesn’t work, gives out an error. I guess, it will only work if my model returns an array.
Is there any way I can shuffle/randomize the data without converting it to an array, or without making the model return an array.
Have you thought about add
$this->db->order_by('id', 'random');when generating the query? The first parameter is the field name and the second the order (possible values are “asc”, “desc”, and “random”). Have a look at theorder_byfunction for more information.EDIT:
Alternatively, you could use
result_array()instead ofresults(). Here’s an example: