shuffle data retrieved from database |
[eluser]chefnelone[/eluser]
Hello, I'd like to shuffle the elements of $data array which is retrieved data from the user table. I tried with shuffle but cant get it working. Is there a way to do this? Code: $data = $this->db->get('alojamientos')->result(); Thanks
[eluser]danmontgomery[/eluser]
Code: $data = $this->db->order_by('random')->get('alojamientos')->result();
[eluser]chefnelone[/eluser]
[quote author="noctrum" date="1287614265"] Code: $data = $this->db->order_by('random')->get('alojamientos')->result(); I tried but I've got the error message: ErrorException [ Fatal Error ]: Error Number: 1054 / Unknown column 'random' in 'order clause' / SELECT * FROM (`alojamientos`) ORDER BY `random` LIMIT 5
[eluser]danmontgomery[/eluser]
sorry, Code: $this->db->order_by('[some field]', 'random')->get('alojamientos')->result(); random needs to be the 2nd parameter, not the first... You just need to specify any field.
[eluser]CroNiX[/eluser]
Heres a good article explaining how order by rand can eat memory with large tables and a great workaround (order by rand creates a temp table of all results first...which might not be good) http://www.paperplanes.de/2008/4/24/mysql_nonos_order_by_rand.html |
Welcome Guest, Not a member yet? Register Sign In |