How to sort date from newest to oldest?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mutzii
Forum Newbie
Posts: 1
Joined: Tue Jan 14, 2014 12:23 am

How to sort date from newest to oldest?

Post by mutzii »

Hi Guys!

I've been trying to find a solution on how to sort the blog posts of my website from newest to oldest. The blog couldn't be found in the data base as I think it was created independently.

Here's the code in the backend:

Code: Select all

<?php 
				//print '<pre>'.print_r($content_list, true).'</pre>';
				print '<ul class="blog-list">';
				foreach ($content_list as $blog_entry){
					print '<li>';
					print '<div class="blog-image"><a href="blog.php?cname='.$blog_entry['name'].'" title="'.$blog_entry['title'].'">'.$blog_entry['image'].'</a></div>';
					print '<h3 class="blog-title"><a href="blog.php?cname='.$blog_entry['name'].'" title="'.$blog_entry['title'].'">'.$blog_entry['title'].'</a></h3>';
					print '<span class="blog-date">'.date('F d, Y', strtotime($blog_entry['date'])).'</span>';
					print '</li>';
				}
			?>
		<?php } else { ?>
Should I just add something in here?? I duno much about PHP.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: How to sort date from newest to oldest?

Post by Celauran »

mutzii wrote:The blog couldn't be found in the data base
Is it stored in a flat file then? Where is $content_list coming from?
Post Reply