Jump to content


Photo

please correct the errors of this php script


  • Please log in to reply
1 reply to this topic

#1 shams

shams
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts

Posted 13 May 2006 - 01:16 AM

hi,
i have mysql table treatment, each patient should come every month to collect his medicens exact in the same date of next month, at least for 8 months, i need a php script that show me the patients didn't collect their medicens after 30 days, these are called defaulters the output of the script will be like this:
john is defaulter from 2006-3-11

this is the incomplete php script for help please any one can complete this one:
<?php
// Make a MySQL Connection
mysql_connect("localhost","root") or die(mysql_error());
mysql_select_db("mydb") or die(mysql_error());
$query = "SELECT name,fatherN,MAX(date) AS Lastdate FROM treatment GROUP BY name, fatherN HAVING TO_DAYS(NOW()) - TO_DAYS(Lastdate) > 30";
$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($result)) {
echo $row['name']." ".$row['fatherN']." "."is defaulter from"." ".$row['Lastdate'];
echo "<br />";
} else { echo "No one is defaulter"; }
?>


#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 14 May 2006 - 09:43 AM

You currently have an ELSE without an IF

Try
<?php
           // do we have any rows returned?
    if ($row = mysql_fetch_array($result))  {
        do {
            echo $row['name']." ".$row['fatherN']." "."is defaulter from"." ".$row['Lastdate'];
            echo "<br />";        
        } while ($row = mysql_fetch_array($result));
    
    }
    else {
        echo "No one is defaulter"; 
    }
?>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users