Jump to content

Archived

This topic is now archived and is closed to further replies.

shams

please correct the errors of this php script

Recommended Posts

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:
[code]
<?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"; }
?>
[/code]

Share this post


Link to post
Share on other sites
You currently have an ELSE without an IF

Try
[code]<?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";
    }
?>
[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.