Here is the current code used to extract data from the database
$query = "SELECT username,time,UNIX_TIMESTAMP(time) as timestamp,UNIX_TIMESTAMP(active) as activestamp,IP FROM ".$table_name." WHERE success='1' ORDER BY active DESC";
Here is a sample set of data (with all unimportant fields removed)
ID | username
_01 | admin
_02 | admin
_03 | bob
_04 | jill
What I want is the total number of times each user appears, for example:
admin (2)
bob (1)
jill (1)
I need to add something along the lines of this COUNT(IF(name = 'admin', 1, NULL)) AS login_totals to the original query I showed you, but I can’t figure out the correct code. The name admin in my sample has to be the current username, so would I just put “username” there?
Try this: I added the
count(*) and the group bytake a look to this Blog: http://www.mysqlperformanceblog.com/2007/04/10/count-vs-countcol/