0

How to stop a cron job after the task is completed?

The job of cron to transfer a set no. of email id's from 1 sql table to another using given specific restrictions. The task executes but does not stop. It re-runs to add duplicate values the table but the limit setting in the php file is not working.

I have posted the code here......

    <?php
    $con = mysql_connect("","","") or die(mysql_error());

    mysql_select_db("email_vijaya",$con) or die(mysql_error());

    session_start();
    ?>
    <?php  $ref = mysql_query("SELECT * FROM Email_Transford_Count WHERE status = '1'"); ?>

    <?php if(mysql_num_rows($ref) == '0')  { ?>

    <?php } else { ?>

    <?php while($yr = mysql_fetch_array($ref)) { ?>

    <?php $actual_Count = $yr['Actual_Count']; ?>

    <?php $Uploaded_ctual = $yr['Rest_Count']; ?>

    <?php $rest = ($actual_Count)*1-($Uploaded_ctual)*1; ?>

    <?php $re = $yr['Rest_Count']; ?>

    <?php  if($actual_Count >= $Uploaded_ctual) { ?>

    <?php $country = mysql_query("select Email_IDs from eData where City = '".$yr['city']."' AND category = '".$yr['category']."' limit $re"); ?>

    <div class="email_css">

    <?php while($u = mysql_fetch_assoc($country)) { ?>

    <?php mysql_query("UPDATE Email_Transford_Count SET Rest_Count = Rest_Count+1 WHERE User_id = '".$yr['User_id']."' AND category = '".$yr['category']."' AND status = '1' "); ?>
    <?php  if($actual_Count >= $Uploaded_ctual) { ?>
    <?php mysql_query("INSERT INTO eData_ClientTransfered VALUES ('','".$yr['User_id']."','".$u['Email_IDs']."','".$yr['category']."','1')"); ?>

    <?php } ?> 
    <?php } ?> 
    <?php  } else { ?>

    <?php mysql_query("UPDATE Email_Transford_Count SET status = '2'      WHERE User_id = '".$yr['User_id']."' AND status = '1'"); ?>


    <?php } ?>

    <?php } ?>

    <?php }  ?>
Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
Badrinath Rao
  • 11
  • 1
  • 3
  • Please, [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement) instead, and use [PDO](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Apr 24 '15 at 19:34
  • Sure....Thanks for the info. I shall update the code with the new format. What about the rest of code......any corrective suggestions for the same? Please help. – Badrinath Rao Apr 24 '15 at 19:45

0 Answers0