爱玺玺

爱玺玺的生活日记本。wx:lb87626

php+mysql 查询最近联系人

 $uid='1602241320282666';
$sql="SELECT * from (
SELECT * FROM (
(SELECT userid as uid,stime FROM u_msg WHERE sender = '$uid')
UNION
(SELECT sender as uid,stime FROM u_msg WHERE userid = '$uid')
ORDER by stime DESC) as tmp GROUP BY tmp.uid ORDER BY tmp.stime DESC limit 2000
) as t LEFT JOIN talk_uinfo as u on t.uid = u.uid";


$iden=mysql_query($sql); 
    while($rsin=mysql_fetch_array($iden)){
    echo $rsin['uid']." ".$rsin['stime']."<br>";
    }



(SELECT userid as uid,stime FROM u_msg WHERE sender = '$uid')
UNION
(SELECT sender as uid,stime FROM u_msg WHERE userid = '$uid')


发送者和接收者字段刚好相对作为条件




发表评论:

Powered By Z-BlogPHP 1.4 Deeplue Build 150101

Copyright Your WebSite.Some Rights Reserved.

蜀ICP备11021721号-5