duandaoji3992 2014-07-24 08:36
浏览 51
已采纳

Sql显示结果为1行而不是重复

Hello i have a table like this

Name  | Date       | Email
------+------------+------
Dima  | 2013-04-01 | email@yahoo.com
Dima  | 2013-07-03 | email@yahoo.com
Dima  | 2013-03-06 | email@yahoo.com
Andrei| 2013-01-28 | testemail@yahoo.com
Andrei| 2013-01-12 | testemail@yahoo.com

echo'<table>';
$stmt = $dbh->prepare("SELECT * FROM Users"); 
$stmt->execute();
while ($row = $stmt->fetch())
            {   
$name=$row['Name'];
$date=$row['Date'];
$email=$row['Email'];
<tr>
<td>'.$name.'</td>
<td>'.$date.'</td>
<td>'.$email.'</td>
</tr>
            }
echo'</table>';

This query will display me the exact table from database, what i want is to display all the info related to Dima for example to one row

Dima \ 2013-04-01, 2013-07-03, 2013-03-06 \ email@yahoo.com

  • 写回答

3条回答 默认 最新

  • dry69034 2014-07-24 08:39
    关注

    you can use GROUP_CONCAT

    SELECT Name, GROUP_CONCAT(Date) Date, Email
    FROM TableName
    GROUP BY Name, Email
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?