php - MySQL UNION with COUNT aliasing -


i trying retrieve 2 counts 2 separate tables 1 sql query use php. current sql query:

select count(entryid) total rh_entries union select count(pentryid) attended rh_playerentries playerid=79 

this php using utilize data: $result = mysql_query($query);

$attendance = mysql_fetch_assoc($result); echo "total: " . $attendance['total']   . " attended: " . $attendance['attended']   . " percentage: "   . (int)$attendance['total'] / (int)$attendance['attended']   . " <br />"; 

i getting output:

warning: division 0 in /home/content/g/v/i/gviscardi/html/guilds/sanctum/raidinfo/player.php on line 41 total: 6 attended: percentage:  

apparently $attendance['attended'] not being set properly. missing on how union or count or works?

union combines contents of 2 queries single table. queries have different column names, merge won't work properly. you'll want like:

select      (select count(entryid) rh_entries) total,      (select count(pentryid) rh_playerentries playerid=79) attended; 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -