PHP SELECT基于状态显示消息

时间:2012-11-21 06:47:41

标签: php mysql sql

t_user
-----------------------------
 uid | username | full_name  
-----------------------------
1    | dodo     | Dodo Ash
2    | jane     | Jane Shalimar
----------------------------


t_join

-----------------------------
j_id | uid_fk | uid | status
-----------------------------
1    | 1      | 2   | joining
2    | 2      | 1   | joining
-----------------------------

t_message
-----------------------------
msg_id | message   | uid_fk
-----------------------------
1      | hi all    | 1
2      | nice trip | 2
-----------------------------

用于显示基于Join的数据的PHP代码:

$query = mysql_query("SELECT M.msg_id, M.uid_fk, M.message, M.created, U.full_name, U.profile_pic, U.username, U.uid, F.status, F.uid FROM t_haps_wall M, t_users U, t_join_user F WHERE
        M.uid_fk=U.uid AND F.uid=U.uid AND F.status='joining' order by M.msg_id desc ") or die(mysql_error());

我遇到了PHP SELECT代码的问题。 关键是如果状态为“加入”,则将显示朋友消息。那么如何才能设置它呢?

1 个答案:

答案 0 :(得分:0)

使用此查询它将起作用。

 $query = mysql_query("SELECT M.msg_id, M.uid_fk, M.message, M.created, U.full_name, U.profile_pic, U.username, U.uid, F.status, F.uid FROM t_haps_wall M, t_users U, t_join_user F WHERE
    M.uid_fk=U.uid AND F.uid=U.uid AND M.uid_fk = F.uid AND F.status='joining' order by M.msg_id desc ") or die(mysql_error());