-1

送信者からの最後のメールだけを印刷したい.これを使用する必要があるPHPコードを次に示します.

$resultmsg=mysql_query("SELECT * FROM mails WHERE  Recieve=$AID GROUP BY Sender DESC ORDER BY ID DESC LIMIT 5 ",$con);
                            while($rowmsg=mysql_fetch_array($resultmsg) )
    {
$authormsg=$rowmsg['Sender'];
$id=$rowmsg['ID'];
$date=$rowmsg['Date'];
$state=$rowmsg['State'];
$sqlnamea=mysql_query("SELECT * FROM users WHERE ID=$authormsg");
                            $datauthor=mysql_fetch_object($sqlnamea);
$authorname=$datauthor->Lname;
$authormsgpic=$datauthor->Profpic;
echo"
<li dir='rtl' style='border-bottom:1px solid silver;";
if($rowmsg['State']=='new')echo "border-right:2px solid #FFAEAF;";
 echo"' class='postedArticle' id='$id postedArticle' ><a href='sendmsg.php?from=".$authormsg."' style='float:right;' target=home><img style='float:right;max-width:40px;max-height:40px;margin-bottom:3px;' src='images/usrimgs/".$authormsgpic."' />&nbsp".$authorname."</a>&nbsp".$rowmsg["Content_text"]."";
4

2 に答える 2

1

制限を1に変更します。

SELECT * FROM mails WHERE Recieve = $ AID GROUP BY Sender DESC ORDER BY ID DESC LIMIT 1

于 2013-03-22T10:07:12.330 に答える
0
  SELECT x.* 
    FROM mails x
    JOIN
       ( SELECT sender,MAX(id) max_id FROM mails GROUP BY sender ) y
      ON y.sender = x.sender
     AND y.max_id = x.id;
于 2013-03-22T10:03:31.133 に答える