本文介绍了MySQL回显具有相同会话ID的记录数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的表是'gallery_list',列是ID,会话ID,通过电子邮件发送到和日期.
My table is 'gallery_list' and columns are ID, sessionid, emailedto, and date.
$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.
This query works just fine, but how can I echo the quantity of records that contain the same sessionid? For example 4 records may contain the same sessionid, I just want to display the number 4.
推荐答案
请参见 http://dev.mysql.com/doc/refman/5.0/en/counting-rows.html
因此您的查询将是
SELECT session_id, COUNT(*)
FROM gallery_list
GROUP BY session_id
这篇关于MySQL回显具有相同会话ID的记录数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!