MySQL Forums
Forum List  »  PHP

Displaying COUNT(*) in a table
Posted by: javid
Date: March 03, 2006 04:56PM

Can anyone tell me if you can display COUNT(*) in a table? Below you can see the query I am using to group by ordertotal displaying count as well as the total count when multiplied. The query has been tested and returns good results.


<?
$query="SELECT ordertotal,pkg_number,COUNT(*),(RIGHT(ordertotal,5)*COUNT(*)) AS total FROM `$db_name` GROUP BY ordertotal";

$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

echo "<b><center>Report for <? echo "$db_name"; ?></center></b><br><br>";

?>
<table border="0" cellspacing="2" cellpadding="2">
<tr>
<th><font face="Arial, Helvetica, sans-serif">Order Total</font></th>
<th><font face="Arial, Helvetica, sans-serif">Package Number</font></th>
<th><font face="Arial, Helvetica, sans-serif">Total Ordered</font></th>
<th><font face="Arial, Helvetica, sans-serif">Total Revenue</font></th>
</tr>


<?
$i=0;
while ($i < $num) {
$ordertotal=mysql_result($result,$i,"ordertotal");
$pkg_number=mysql_result($result,$i,"pkg_number");

****/ Not sure what to do here/****
$count(*)=mysql_result($result,$i,"count()");

$total=mysql_result($result,$i,"total");
?>

<tr>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$ordertotal"; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$pkg_number"; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$count(*)"; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$total"; ?></font></td>
</tr>
<?
++$i;
}
echo "</table>";


?>

I get the following error:
Parse error: parse error, unexpected '*', expecting ')'


Any suggestions would be appreciated.

Options: ReplyQuote


Subject
Written By
Posted
Displaying COUNT(*) in a table
March 03, 2006 04:56PM
March 03, 2006 05:10PM
March 03, 2006 05:10PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.