Forum Moderators: coopster

Message Too Old, No Replies

how to get total of this output?

how to get total of this output?

         

shams

2:04 am on May 22, 2006 (gmt 0)

10+ Year Member



hi,
there is treatment table, each patinet get his drugs monthly for some months, this script get the drug name and treatment period for that drug as input, and output the total of drugs needed for each patient in the rest of months, like this:
Abudllah need more 90 tables of PZA
qader need more 270 tables of PZA
zubair need more 360 tables of PZA
i want a script to output the total of above reault, this is script:
<?php
error_reporting(E_ALL);
$drug = $_POST['drug'];
$period = $_POST['period'];
mysql_connect("localhost","root") or die(mysql_error());
mysql_select_db("mydb") or die(mysql_error());

$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 />";
}
?>

eelixduppy

2:26 am on May 22, 2006 (gmt 0)



Change it to this:

$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;

shams

11:19 am on May 22, 2006 (gmt 0)

10+ Year Member



hi eelixduppy,
thanks for help, your script works perfect.