0

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>
2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by Will Gresham
2

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.