How to order data from newest to oldest |
[eluser]Michal1[/eluser]
Hi guys I slowly leak into the codeigniter and here is a thing I am not sure about. I am basically getting data from my database and then showing them in a view. I am using a simple foreach loop. Code: <?php if(isset($records)) : foreach($records as $row) :?> The thing is that articles (records) are ordered in the way, that oldest articles are on the top and the newest on the bottom. But of course I need to have it opposite, so it should go from newest at the top to oldest at the bottom like every other CMS. I am pretty sure this will just require a little edit, but I dont know what to do. COuld somebody help? Thank you very much
[eluser]Bart v B[/eluser]
I think you can better do that in your sql statement. Something like: ORDER BY datefield ASC or DESC. You can play with ASC and DESC one does the newest and the other the oldest. But i forget witch one you need. ![]()
[eluser]mi6crazyheart[/eluser]
If u r using CI active records to make u'r sql query just use "$this->db->order_by()" in u'r model function. ha ha, most probably that might be "DESC" Example: Code: $this->db->order_by("dateField", "desc"); Ref: http://ellislab.com/codeigniter/user-gui...ecord.html
[eluser]Michal1[/eluser]
Thanks guys. For getting a data from database I got this functin in a model class Code: function get_records()
[eluser]Bart v B[/eluser]
Then it would be something like this: Code: <?php
[eluser]Michal1[/eluser]
thank you Bart. I did it needlesly too much difficult :-). |
Welcome Guest, Not a member yet? Register Sign In |