dreigon Posted April 27, 2010 Share Posted April 27, 2010 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 More sharing options...
Synook Posted April 27, 2010 Share Posted April 27, 2010 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 More sharing options...
dreigon Posted April 28, 2010 Author Share Posted April 28, 2010 Thanks so much , That worked well. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.