MySQL回显具有相同会话ID的记录数

时间:2014-02-10 22:09:56

标签: php mysql

我的表是'gallery_list',列是ID,sessionid,emailedto和日期。

$query = mysql_query("SELECT DISTINCT sessionid, emailedto, date FROM gallery_list ORDER BY date DESC") or die(mysql_error());

echo "<table>";

while($row = mysql_fetch_assoc($query)){

    echo "<tr>";
    echo "<td><a href='?gallery=".$row['sessionid']."'>VIEW GALLERY SELECTION</a></td>";
    echo "<td>".$row['emailedto']."</td>";
    echo "<td>".$row['date']."</td>";
    echo "<td>".$record_count."</td>";
    echo "</tr>";

}

echo "</table>";

此查询工作正常,但如何回显包含相同sessionid的记录数量?例如,4条记录可能包含相同的sessionid,我只想显示数字4。

2 个答案:

答案 0 :(得分:2)

请参阅http://dev.mysql.com/doc/refman/5.0/en/counting-rows.html

所以你的查询将是

SELECT session_id, COUNT(*)
FROM gallery_list
GROUP BY session_id

答案 1 :(得分:-1)

SELECT  sessionid, count(*) as count, emailedto, date FROM gallery_list GROUB By sessionid ORDER BY date DESC