SUCCESSGANDE SUCCESSGANDE - 3 months ago 7
MySQL Question

php Calculating Remaining Days from Database

I have a table named 'treat_period' for storing fix number of days for each goat to reach for vaccination and an order_details table for storing information for when the goat was purchased.
Now the treat_period table has the following as columns with corresponding data; id(1), productID(goat), treat1(90), treat2(180), treat3(270), treat4(360), annualtreat(365). I want to know whether the goat has stays for 90, 180 days respectively.
Here is my code, Please help.

<?php
$treat_query = mysql_query("select * from treat_period where productID='$product_id'") or die(mysql_error());
$treat_row = mysql_fetch_array($product_query);
$treatperiod1=$treat_row['treat1'];
$thisDate = date("Y-m-d");
$allDays = $treatperiod1;
$usedDays = round(abs(strtotime($thisDate)-strtotime($orderdate))/60/60/24);
$Daysremaining = $allDays-$usedDays;
if($Daysremaining==0)
{
echo "<a target = '_blank' href ='request_pay.php?order_id=$order_id&orderdate=$orderdate' class='btn btn-success'><i class='fa fa-pencil'></i>Vaccinate Gaoat</a>";
}
else
{
echo $Daysremaining.' Days Left for Vaccination';

}

?>

Answer
 $Daysremaining = ceil(abs(strtotime($thisDate) - strtotime($orderdate)) / 86400);
    if($treatperiod1==$Daysremaining){
       echo "<a target = '_blank' href ='request_pay.php?order_id=$order_id&orderdate=$orderdate' class='btn btn-success'><i class='fa fa-pencil'></i>Vaccinate Gaoat</a>";
    }else {
      echo $Daysremaining.' Days Left for Vaccination';
    }