0

I created a table that contains message, sender, to, time I want to echo message ordered by time that is my code.

$query= mysql_query("SELECT * FROM  `table` GROUP BY `sender` ORDER BY `time` DESC")or die(mysql_error());
while($arr = mysql_fetch_array($query)){
$num = mysql_num_rows($query);
$msg = $arr ['message'];
echo '</br>';
echo $msg;
}

that shows me the first message from each sender I want to show the last message from each sender, So how can I do this

Thanks :)
Klaus

Klaus Jasper
  • 89
  • 1
  • 3
  • 9
  • It shows not first but "*some*" message from each sender. It's not guaranteed to be the first. – zerkms Jul 01 '13 at 01:25

1 Answers1

1

try this :

SELECT * FROM  (select * from table order by `time` desc) t1 GROUP BY `sender` 
Daniel Robertus
  • 1,100
  • 1
  • 11
  • 24