0

I want to show user that he has vaccinated his goat after successfully payment confirmation.
Here is what I tried:

<?php
$treatperiod1=$product_row['treat1'];
$currentDate = date("Y-m-d");
$totalDays = $treatperiod1;
$usedDays = round(abs(strtotime($currentDate)-strtotime($orderdate))/60/60/24);
$remainingDays = $totalDays-$usedDays;

if($remainingDays==0) {
    echo "<a target = '_blank' href ='product_addon.php?treatp=$treatperiod1' class='btn btn-success'><i class='fa fa-pencil'></i>Vaccinate Gaoat</a>";
} elseif($remainingDays==$treatperiod1) {
    echo 'Vaccinated';
} else {
    echo $remainingDays.' Days Left';         
}

?>

I have displayed remaining days for vaccination intervals I want to also display 'Vaccinated' if user payment for vaccination is confirmed. $product_row['treat1']; is a column where the number of days for vaccination is specified. order_details is a table for orders with column confirm for confirmed orders.

3
  • if a user 'vaccinetes' the goat, do you save anything on you DB? Commented Sep 12, 2016 at 15:22
  • Yes, in order_details table under confirm Commented Sep 12, 2016 at 15:22
  • I have tried this but could not work elseif($remainingDays==0 || $order_status=='Delivered') Commented Sep 12, 2016 at 15:41

1 Answer 1

1

Goat Vaccination:
Because Goats don't get Autism

Please read how to use PHP DateTime objects because they will make your life a lot easier on this project.

I will rewrite your code and then tell you what the new code does:

//establish DateTime objects. 
$currentDate = new DateTime(); //now.
$orderDate   = new DateTime($orderdate); //$orderdate format Y-m-d

//Establish how may days since order date and today.
$difference  = $orderDate->diff($currentDate);
$usedDays    = $difference->days;  

/*** 
 Total Period paid for,
 in days, integer.  
 $product_row['treat1'];
 ***/

 $remainingDays = $product_row['treat1'] - $usedDays;
 //Returns an integer value of remaining days. 


if($remainingDays < 1) {
    echo "<a target = '_blank' 
          href ='product_addon.php?treatp=".$treatperiod1."'>
          Vaccinate Goat</a>";
} elseif($remainingDays==$product_row['treat1']) {
    //This will only fire if the goat was vaccinated TODAY.
    echo 'Vaccinated';
} else {
    echo 'Vaccinated:' .$remainingDays.' Days Left';         
}

Hopefully with the help of the link above you should be able to see the basics of what I wrote out for you.

Some notes:

  • Stop making variables that are simply copies of other variables, it's inefficient and confusing.

  • (Try to) Stop sending data to new PHP pages as GET URL values such as /newpage.php?treatp=".$var.". This is very probably very insecure.

  • A more specific answer will need a full explanation from you of your MySQL tables, if nessecary please edit your question and add them.

  • Try and move away from using timestamps and treating timestamp variables as mathematical entities, and use the DateTime object instead.

  • Really, to determine if a payment is made you should have a payment date value in your database (set when a payment is successful) and simply compare this date to the value of the integer of the number of days payment covers, using the ->diff() method illustrated above.

enter image description here

Further information on Goat Vaccinations

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.