I’ve made a microblog system (like Twitter) using PHP and MySQL. Every time someone posts an item it includes the UNIX timestamp in the database. But my question is, how do i get the newest item on top of the page, the second to newest as second, etc? So basically, the one with the ‘highest’ timestamp on top of the page, the one with a bit ‘less’ timestamp under that.
This is what I got (I know mysql_ functions are deprecated):
<?php
/*Database test.
© 2013 Sydcul. All rights reserved.
To set the database settings, use the 'install' directory*/
include ($_SERVER['DOCUMENT_ROOT'] . '/test/config.inc.php');
$connection = mysql_connect($host, $user, $password);
mysql_select_db($database, $connection);
$messages = mysql_query("SELECT * FROM `" . $prefix . "microblog`");
while($row = mysql_fetch_array($messages))
{
$names = mysql_query("SELECT first_name,last_name FROM `" . $prefix . "data` WHERE id='" . $row['id'] . "'");
$name = mysql_fetch_assoc($names);
$fullname = $name['first_name'] . " " . $name['last_name'];
echo "<h2>Posted by " . $row['id'] . " (" . $fullname . ")</h2>";
echo $row['message'] . "<br><br>";
}
mysql_close($connection);
?>
Please explain how to do it, instead of only giving me code, otherwise I and the other people on stackoverflow can’t learn from it 🙂
Use
ORDER BYin your SQL