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))
{
if($row[$drug] < $period) {
echo $row['name']." need more ".(($period - $row['needed']) * $row[$drug])." tables of ".$drug;
echo "<br />";
} else { echo "ATT Completed";}
}
?>
$query = "SELECT name,$drug,count($drug) as needed FROM treatment group by name,$drug";
Aren't the table fields fixed? Why $drug;
If you rewrite the query to:
$query = "SELECT name,drug,count(drug) as needed FROM treatment group by name,drug";
Then you might use to $row[drug] to display them.
But explain why you want the $drag to be variable, and I believe that is where the problem lies.
Habtom
if($row[$drug] < $period) {
i assume you mean $row[$drug] is a word, right? Like the name of a drug? And i assume $period is a numerical value, because it seems you are mesuring a word against a number
I think you want the number of rows for the drug right?
Try
while($row = mysql_num_rows($result))
{
if($row['drug'] < $period) {
echo $row['name']." need more ".(($period - $row['needed']) * $row['drug'])." tables of ".$drug;
echo "<br />";
} else { echo "ATT Completed";}
}
//With test echo
while($row = mysql_fetch_array($result))
{
echo $row[$drug];
if($row[$drug] < $period) {
echo $row['name']." need more ".(($period - $row['needed']) * $row[$drug])." tables of ".$drug;
echo "<br />";
} else { echo "ATT Completed";}
}
Hab
1) count(PZA) gives a number of records (the number of records in the table for each patient and each PZA value); if there is one record for each patient, count(PZA) will always be 1; if there are 2 records for patient 'JD', and PZA values are the same, count(PZA) will be 2; if you have more than one record by patient you probably want to use sum(PZA); if you have one record by patient "SELECT name, PZA FROM treatment" is enough
2) if your script just outputs "ATT Completed " once, that means your query returns only one record with PZA value greater than $period received
3) as you do not give an ORDER clause in your query, it is unlikely that that patients having completed their period of treatment should first be excluded
Hope it will help.