S
S
step-olga2015-06-22 17:43:56
PHP
step-olga, 2015-06-22 17:43:56

Did I write the processing script correctly, comparing dates with subsequent processing?

Tell me, please, there is a database with a list of employees, there is a table with the task and the date by which this task must be completed. If the task is not completed by the date, the value in the field changes to "Not completed", and points are deducted from this employee in another table. What I could write: I made a database selection by date, if the date is equal to the current one, I make a query to the database. The script will run on the cron. But how to make the script repeat until it checks all the tasks. Please look at the code, maybe there is a simpler solution?

<?php
    
    $date = date('Y-m-d');
    $com = 'Не выполнено';
     
     
     $db = mysql_connect($mysql_server, $mysql_username, $mysql_password);
     mysql_select_db($mysql_database, $db) or die('Failed to select database<br>'.mysql_error());
     $sql = "SELECT * FROM `zadanie` WHERE data = '$date'";
     $result = mysql_query($sql, $db);
      while ($res = mysql_fetch_array($result))
     {
            $id =   $res['id']
            $id_user    = $res['id_user'];
            $nomer = $res['nomer'];
            $data = $res['data'];
            $zadanie = $res['zadanie'];
            $day    = $res['day'];
            $up_data = $res['up_data'];
    }
    
    if($date == $up_data) 
            { 
            mysql_select_db($mysql_database, $db) or die('Failed to select database<br>'.mysql_error());
         $sql = "UPDATE `users` SET `bal` = `bal` - 10 WHERE `id` = '$id_user'";
            mysql_query($sql, $db);
         $sql = "UPDATE `zadanie` SET `up_data` = $com WHERE `id` = '$id'";
            mysql_query($sql, $db);
            }
?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DevMan, 2015-06-22
@step-olga

put the test inside the loop (that is, in the while).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question