2017-07-02 50 views
0

对我来说这里有点困难。我的评论是针对行号显示的许多行而打破的。不幸的是,我无法控制这个,所以我仍然试图以他们想要的方式输出。PHP Mysql显示并加入行

我的数据是遵循

Firstname | Surname | Linenum |CommentID | Comment 
-------------------------------------------------------------------------- 
Bill  | Jean | 0  |8876  | A Simple comment here 
-------------------------------------------------------------------------- 
Bob  |Jones | 0  |7345  | This is a very long comment 
-------------------------------------------------------------------------- 
Bob  |Jones | 1  |7345  | And is over many rows. 
-------------------------------------------------------------------------- 
Bob  |Jones | 2  |7345  | Thank you for reading. 
-------------------------------------------------------------------------- 
Tim  |Burton | 0  |3719  | The quick brown fox jumps 
-------------------------------------------------------------------------- 
Tim  |Burton | 1  |3719  ! over the lazy dog 
-------------------------------------------------------------------------- 

我想是呼应落得那么什么.....

Firstname: Tim 
Surname : Burton 
Comment : The quick brown fox jumps over the lazy dog 

我真的很粘在SQL,这和唐”不知道从哪里开始。

我可以调用并显示MySQL,我会正常调用!但是当它呼吁从几行加入时,我感到茫然。

谢谢你看!

+0

你能发表一个你的MySQL表的例子吗?什么是列名? –

回答

0

你需要这样的查询:

SELECT firstname, surname, 
    GROUP_CONCAT(comment) as comment from table 
    where commentid=3719 
    group by firstname, surname 
+0

谢谢穆罕默德!真的appreaciated。 –

1

您的查询乞求group_concat。您将需要编写一个选择,其中将有

order by CommentID, Linenum 

这将是子选择。外部选择将使用group_concatComment

group by CommentID