Jump to content

Display table rows in reverse order ?


dreigon

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...