t_message
msg_id
消息
用户名
date_post
url
t_comment
com_id
评论
msg_id
用户名
date_comment
url
如何显示基于msg_id的评论?例子:
约翰发了言:欢迎来到我的世界。然后简评论了他的信息:也欢迎你。
格雷格也评论道:欢迎老板.
其他简发了言:我今天很高兴。
然后格雷格评论她的留言:哇..。
应该是每一个都会有不同的表演对吧?
有什么建议吗?
发布于 2012-08-14 06:34:27
基于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发布于 2012-08-14 06:42:53
你可以用这样的方式
//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";
}
}https://stackoverflow.com/questions/11946878
复制相似问题