posting the latest of something to the top of the row |
[eluser]mdriscol[/eluser]
Hi, I'm new to this. I have a page displaying data from a table with foreach($announcements->result() as $row): When its displayed each new row is displayed below the oldest but I want to do that in reverse order. The newer posts need to be on the top instead of the bottom of the table. How can I accomplish this? Should I be using a function that reorders the table in the database or a function that displays foreach in reverse on the view?
[eluser]Unknown[/eluser]
I would check the user guide (http://ellislab.com/codeigniter/user-gui...ecord.html) for the Active Record class and use $this->db->orderby(); passing the date stamp or id or whatever column you are trying to order by. Of course, if you are using a query directly rather than Active Record, just include the ORDER BY clause in your SQL. You shouldn't need to do anything with the array itself or any additional code.
[eluser]mironcho[/eluser]
You can use in your sql query ORDER BY id DESC (if your id filed is id) or AR way: Code: $this->db->orderby('id', 'DESC'); or you can retrieve results array with $announcements->result_array(), and then reverse it with php build in function array_reverse();
[eluser]Unknown[/eluser]
Thx, the $announcements->result_array() way is very useful! |
Welcome Guest, Not a member yet? Register Sign In |