t_message
MSG_ID
消息
用户名
date_post
网址
T_COMMENT
com_id
评论
MSG_ID
用户名
date_comment
URL
如何根据msg_id显示评论?
示例:
其他简已发布消息:我今天很开心。
然后Greg评论了她的信息:哇......
应该是每个人都会有不同的表现吗?
有什么建议吗?
答案 0 :(得分:1)
根据msg_id
检索评论SELECT c.comment,c.username from t_comment c
left join t_message m on c.msg_id=m.msg_id
where c.msg_id={your msg id}
order by c.date_comment
根据msg_id
检索评论和消息select * from
(select m.message,m.username,m.date_post as date_p,m.msg_id from t_message m
union
SELECT c.comment,c.username,c.date_comment as date_p,c.msg_id from t_comment c
left join t_message m on c.msg_id=m.msg_id )t
where t.msg_id={your msg id}
order by t.date_p
答案 1 :(得分:0)
你可以这样使用,
//Do your connect operations here
$sql_message = "SELECT * FROM t_message;
$result = mysql_query($sql_message);
while ($row = mysql_fetch_assoc($result)) {
echo "\nMessage : " . $row["message"] . "\n";
echo "-----Comments : \n";
$sql_comment = "SELECT * FROM t_comments where msg_id = " . $row["msg_id"];
$result_comments = mysql_query($sql_comment);
while ($row_comments = mysql_fetch_assoc($result_comments)) {
echo $row_comments["comment"] . "\n";
}
}