Forum Moderators: coopster
$query = "SELECT name,$drug,count($drug) as needed FROM treatment group by name,$drug";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result))
{
echo $row['name']." need more ".(($period - $row['needed']) * $row[$drug]). " tables of ".$drug;
echo "<br />";
}
?>
$total = 0;
while($row = mysql_fetch_array($result))
{
$amount = (($period - $row['needed']) * $row[$drug]);
$total = $total+$amount;//or $total += $amount;
echo $row['name']." need more ".$amount." tables of ".$drug;
echo "<br />";
}
echo "Total: ".$total;