PDA

View Full Version : SELECT COUNT - MySQL


Benumbed
02-12-2005, 04:49 PM
$eventattendees = $DB_site->query("SELECT COUNT (raid_id) AS totalcount FROM dkp_raids r, dkp_raid_attendees a WHERE r.raid_id=a.raid_id");

Trying to get count of attendees where raidid = raidid of the raid I am viewing. Hope that makes sense. Thanks in advance

Dean C
02-12-2005, 05:08 PM
Try adding a GROUP BY raid_id at the end :) Be sure to group it by the fieldname on the right table. I noticed you have aliases there and hence you should use them to avoid ambigous field errors :up:

Benumbed
02-12-2005, 05:14 PM
$eventattendees = $DB_site->query("SELECT COUNT(raid_id) AS count FROM dkp_raid_attendees WHERE raid_id='2' GROUP BY raid_id");

I tried that, and I am getting this:

Recorded Raid History for Upper Blackrock Spire
Date Attendees Drops Notes Added by Value
02-12-05 Resource id #26 Raid #2 Renwo 15.00
02-11-05 Resource id #26 First raid Renwo 15.00

(Notice the resource id) I have also removed the alias and just imputting a number there for time being to avoid any other problems.

Dean C
02-12-2005, 05:18 PM
Change $DB->query to $DB->query_first and access the variable with $eventattendees['count'] :)

Benumbed
02-12-2005, 05:25 PM
Thanks so much :)

Dean C
02-12-2005, 06:43 PM
Glad you got it sorted :)