我似乎无法正确显示此查询。这是代码:
$select_stats = "SELECT
c.ResponderID
, COUNT(MsgID)
, a.SubscriberID
, CanReceiveHTML
, EmailAddress
FROM InfResp_msglogs AS a
, InfResp_subscribers AS b
, InfResp_responders AS c
WHERE b.CanReceiveHTML = 1
AND c.owner='".$_SESSION['logged_user_id']."'
AND c.ResponderID = b.ResponderID
AND b.SubscriberID = a.SubscriberID
GROUP BY c.ResponderID";
//echo $select_result;
while($row = mysql_fetch_array($select_result))
{
$messages = $row['COUNT(MsgID)'];
$campaign = $row['ResponderID'];
$subscriber = $row['SubscriberID'];
$subscriber_email = $row['EmailAddress'];
echo "<br>Campaign = ". $campaign ."
<br>Sent emails count = ". $messages ."
<br>Subscriber Nr. = ". $subscriber ."
<br>Subscriber Email = ". $subscriber_email ."<br>";
}
这是输出:
Campaign = 10
Sent emails count = 109
Subscriber Nr. = 95
Subscriber Email = [email protected]
Campaign = 11
Sent emails count = 16
Subscriber Nr. = 97
Subscriber Email = [email protected]
由于数据库中第10个广告系列下有三个不同的订阅者,而第11个广告系列下有一个不同的订阅者(当然每个订阅者都有自己的电子邮件地址),我希望输出为:
Campaign = 10
Sent emails count = 109
Subscriber Nr. = 92
94
95
Subscriber Email = [email protected]
[email protected]
[email protected]
Campaign = 11
Sent emails count = 16
Subscriber Nr. = 97
Subscriber Email = [email protected]
谢谢。
最佳答案
为此,您需要group_concat:
... SELECT c.ResponderID, COUNT(MsgID), a.SubscriberID, CanReceiveHTML,
group_concat(EmailAddress ORDER BY EmailAddress DESC SEPARATOR ' ') ...