大家好,我有一张桌子
“评论”如下
commentid cmt followupid category
1 hello 3 starting
2 hi how are you 4 starting
3 Hello Jhon 5 followup
4 Hi I am fine and you 6 followup
我希望回复记录,以便当我回显Hello
时,将显示的下一个评论为Hello John
,当我回显Hi how are you
时,将显示的下一个评论为{{1} }}。
我试过
Hi I am fine and you
但它不起作用。
答案 0 :(得分:0)
指定的查询将获得followupid等于commentid的结果,并且您的示例中没有任何结果。
要使它工作,您需要明确指定您正在寻找的纪念品:
SELECT * FROM comment where category = 'followup' AND followupid = 3
如果是PHP,你可以从你正在打印的当前记录中得到这个:
echo $row['cmt'];
mysql_query("SELECT * FROM comment where category='followup' and followupid={$row['followupid']}");
答案 1 :(得分:0)
尝试使用SELF JOIN
SELECT cb2.comment AS message, cb1.comment AS response
FROM `chat_box` cb1
INNER JOIN chat_box cb2 ON cb2.followup_id = cb1.comment_id
LIMIT 0 , 30
将返回
Message | Response
Hello |Hello John
Hi, how are you Hi, | i am fine and you