i wish to count the number of rows with a given content, group them by one of the columns and print the results:
code:
$countdet=mysql_query("SELECT size, COUNT(*) FROM Details WHERE mapLoc = '$rowloc[id]' GROUP BY size") or die(mysql_error());
while($rowcd=mysql_fetch_array($countdet)){
switch($rowcd[size]){
case "GP":
echo "<img src=\"GP.png\"> $rowcd['COUNT(*)'] Gigapixel images<br>";
break;
case "L":
echo "<img src=\"L.png\"> $rowcd['COUNT(*)'] large images<br>";
break;
case "M":
echo "<img src=\"M.png\"> $rowcd['COUNT(*)'] medium images<br>";
break;
case "S":
echo "<img src=\"S.png\"> $rowcd['COUNT(*)'] small images";
break;
}
}
as above, i get the error:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
and if i change $rowcd['COUNT(*)'] to $rowcd[COUNT(*)] i get the error: unexpected ( was expecting ].
any ideas? i just want it to return the value of the count... the mysql query works fine when i put it in, and the line number on the errors point to this bit of the code
TIA
edit: the example on this (http://www.tizag.com/mysqlTutorial/mysqlcount.php) is pretty much what i want to achieve, but am failing to do
code:
$countdet=mysql_query("SELECT size, COUNT(*) FROM Details WHERE mapLoc = '$rowloc[id]' GROUP BY size") or die(mysql_error());
while($rowcd=mysql_fetch_array($countdet)){
switch($rowcd[size]){
case "GP":
echo "<img src=\"GP.png\"> $rowcd['COUNT(*)'] Gigapixel images<br>";
break;
case "L":
echo "<img src=\"L.png\"> $rowcd['COUNT(*)'] large images<br>";
break;
case "M":
echo "<img src=\"M.png\"> $rowcd['COUNT(*)'] medium images<br>";
break;
case "S":
echo "<img src=\"S.png\"> $rowcd['COUNT(*)'] small images";
break;
}
}
as above, i get the error:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
and if i change $rowcd['COUNT(*)'] to $rowcd[COUNT(*)] i get the error: unexpected ( was expecting ].
any ideas? i just want it to return the value of the count... the mysql query works fine when i put it in, and the line number on the errors point to this bit of the code
TIA
edit: the example on this (http://www.tizag.com/mysqlTutorial/mysqlcount.php) is pretty much what i want to achieve, but am failing to do
Last edited: