I have a little twitter clone but how to display messages from mysql from newest to oldest.

<?php
session_start();
$connect = mysql_connect ("localhost","root","") or die (mysql_error());
mysql_select_db ("login4") or die (mysql_error());

$_SESSION['username'];
$username1 = $_SESSION['username'];
$username = $_POST['username'];
$submit = $_POST['submit'];
$micro = $_POST['micro'];
$date = date("d-m-Y");
if ($submit){
mysql_query("
INSERT INTO micro VALUES ('','$username','$micro','$date')
");
}
?>
<?php
$query = mysql_query ("SELECT * FROM micro");
while ($row = mysql_fetch_array($query)){
$username = $row['username'];
$micro = $row['micro'];	
echo "".$username."<br />".$date."</div><br />".$micro."<br />";
}
?>
<form action="micro.php" method="post">
<input type="text" value="<?php echo $username1 ?>" name="username" readonly="readonly" id="username" />
<br />
<textarea  name="micro" id="micro"></textarea>
<br />
<input type="submit" name="submit" value="Blab" />
</form>

Rather than using

$date = date("d-m-Y");

Save the date as a timestamp in an int(11) field, do not save dates as DATETIME, DATE or any other date specific SQL type..
Since this will be a number, you can then sort by the date column in descending order to get newest to oldest :)

Simply use your $date = date("d-m-Y"); on the timestamp when you display the information.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.