JONxBLAZE
JONxBLAZE

Reputation: 81

MySQL echo number of records that has the same session 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>";

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.

Upvotes: 0

Views: 430

Answers (2)

Tero Lahtinen
Tero Lahtinen

Reputation: 524

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

Upvotes: -1

abl
abl

Reputation: 5958

See http://dev.mysql.com/doc/refman/5.0/en/counting-rows.html

So your query would be

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

Upvotes: 2

Related Questions