I was trying to build a chat plugin in my site but I got problem while sorting the incoming messages in the Inbox. When I use the code below, it doesn't order the messages according to new sent but orders according to history of sent messages:
E.g. if I send message to "A" at first, "B" after that and "C" at last, the code I works fine up to here. It shows C at Top, B at middle and A at end. But When I again send message to B, the "B" doesn't come up at the top.
Edit: Someone tagged this question as duplicate. The problem about that question is abit different. I already did extract the unique row (as asked by that question) but I cannot sort it according to time.
Here is the code I use and please ignore the mysql_* tag I used here. It is just for testing.
<?php
$sql = mysql_query("SELECT DISTINCT `from` FROM `message` WHERE `to`='$username' ORDER BY `time` DESC");
// using loop
while($row = mysql_fetch_assoc($sql)){
echo $row['from'];
echo "<br/>";
}
?>