Forum Moderators: coopster

Message Too Old, No Replies

please correct the errors of this php script

please correct the errors of this php script

         

shams

12:06 pm on May 21, 2006 (gmt 0)

10+ Year Member



hi,
there is mysql table treament, each patient will get his drug monthly for a period of months, this php script will get the drug name and the number of period of months as input, will print the ouput of, how many more months left for each patient ot get that drug, when i run this the ouput is:
Abudllah need months ATT
qader need months ATT
zubair need months ATT
the answer is not correct:
<?php
$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,count($drug) FROM treatment group by name";
$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($result))
{
if($row[$drug] < $period) {
echo $row['name']." need ".$row[$period - $durg]. " months ATT";
echo "<br />";
} else { echo "ATT completed"; }
}
?>

henry0

12:40 pm on May 21, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



echo $row['name']." need ".$row[$period - $durg]. " months ATT";

Is it a new medication $DURG :)

dreamcatcher

1:26 pm on May 21, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



hee hee. shams, always set your error reporting to E_ALL for development. This will help you identify problems.

So, after your opening <?php tag add:

error_reporting(E_ALL);

dc

shams

1:39 pm on May 21, 2006 (gmt 0)

10+ Year Member



thanks for replies, i changed the $durg to $drug and also sdded the phrase error_reporting(E_ALL); after <?php but still the output of script is above one:
Abudllah need months ATT
qader need months ATT
zubair need months ATT
can't print the numbers of months, any help please?

shams

2:48 pm on May 21, 2006 (gmt 0)

10+ Year Member



thanks to all finally i solved the problem this is woking now:

$query = "SELECT name,count($drug) as needed FROM treatment group by name";
$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($result))
{
echo $row['name']." need ".($period - $row['needed']). " months ATT";
echo "<br />";
}
?>

henry0

2:58 pm on May 21, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Glad you won't need any more Aspirin!