Jump to content

Display table rows in reverse order ?


dreigon
 Share

Recommended Posts

I'm Using the following PHP code with SQLite to output my blog posts to a page. However, I want to show the latest one first, so I need to reverse the order that they are displayed. The code is working fine otherwise.

<?php$x = new PDO("sqlite:my_db.sqlite");$r = $x->query("SELECT * FROM Blog");foreach($r as $d) {    echo "<p>".$d['Day']." ".$d['Month']." ".$d['Year']."<br />".$d['Title']."<br />".$d['Post']."<br /><a href=\"editPost.php?postID=".$d['postID']."\">Edit Post</a> || <a href=\"deletePost.php?postID=".$d['postID']."\">Delete Post</a></p>";}?>

If you could help that would be great.Thanks

Link to comment
Share on other sites

Use the ORDER BY clause. For example, if you want to show them by their date field, DESCending, you could do:

//...$r = $x->query("SELECT * FROM Blog ORDER BY date DESC");//...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...