dumebi dumebi - 1 year ago 55
MySQL Question

fetch associative column value in select count(*) statement

Please i am trying to fetch the associative column value on a select count(*). here is my code.

$res = mysql_query("select count(*) as total from table where reg = '12' GROUP BY YEAR DESC LIMIT 7");
while($r4 = mysql_fetch_assoc($res)){

$totalscore = $r4['AVERAGE'];
$len = $r4['total'];

returns my expected value, while the column AVERAGE is undefined i.e
$totalscore = $r4['AVERAGE'];
AVERAGE is a column on my database. Does it mean i cannot fetch associative column value if my sql statement is count(*)?? any ideas?

Answer Source

You did not select the average column in your query you can select more columns like so:

   COUNT(*) as total,
   FROM table 
   WHERE reg = '12' 
   LIMIT 7