0

I have created a script that gets all the sales from database and compares if the days left in sale is in negative or less than 0.2 then it would update it's status column as Inactive. It is running great!

<?php
include_once '../includes/db_connect.php';
$stmtgetallsales = $mysqli->prepare("SELECT * FROM store_sales");
$stmtgetallsales->execute();
$getallsales = $stmtgetallsales->get_result();
$stmtgetallsales->close();

while ($allsales = $getallsales->fetch_assoc()) {
    $db_date =  join('-',array_reverse(explode('-',$allsales['sale_till'])))." ".$allsales['created_time'];
    $check = get_date($db_date);

    if ($check < 0 || $check <= 0.2) {
        $stmtupdatesale = $mysqli->prepare("UPDATE store_sales SET status='Inactive' WHERE sale_id = ?");
        $stmtupdatesale->bind_param("i", $allsales['sale_id']);
        $stmtupdatesale->execute();
        $stmtupdatesale->close();
    }
}
function get_date($old) {
    $offset=5*60*60;
    $timeFormat="H:i";
    $time=gmdate($timeFormat, time()+$offset);
    $now = date("Y-m-d");

    $dateOldd = $now." ".$time;

    $dateCurrent = new DateTime($dateOldd);
    $dateNew = new DateTime($old);

    $difference_in_seconds = $dateNew->getTimestamp() - $dateCurrent->getTimestamp();

    return $total_difference_in_days = $difference_in_seconds / 86400;
}

?>

Now I have to run this script in my hosting. I have this panel in front of me

panel of cronjob

I am going to run this script once per hour every 24 hours every day

What settings should I put and what to write in Command line.

I am new to cronjob. THank you for help!

Ivan
  • 2,463
  • 1
  • 20
  • 28
Ali Rasheed
  • 2,765
  • 2
  • 18
  • 31
  • This should help: http://stackoverflow.com/questions/28235524/how-to-run-a-php-script-daily-with-the-cron-job-on-ubuntu-os – rob2universe Jan 11 '17 at 13:51
  • Possible duplicate of [how to run a php script daily with the cron job on Ubuntu os](http://stackoverflow.com/questions/28235524/how-to-run-a-php-script-daily-with-the-cron-job-on-ubuntu-os) – rob2universe Jan 11 '17 at 13:52

1 Answers1

0

if php 5.6

/opt/php56/bin/php /home/username/public_html/cron.php

Ali Rasheed
  • 2,765
  • 2
  • 18
  • 31