-1

Here, I like to explain my problem clearly, I have table called claims in that there is field called TRT(turn around time). In this field user set a date(example: 2015-07-09), Every time admin used to check a pendings availble or not, example: if today's date and TRT date is same then the Pending data automatically moves to another table.

so what i did is ,

$today = date('Y-m-d');
$dt1 = ArrayHelper::map(Importclaims::find()->all(),'id','turn_around_time_set');

foreach ($dt1 as $key => $value) 
        {
            $trt = print_r($value, true);

            if($today == $trt)
            {
                $sql = "INSERT INTO importpending (claimer_name, status, template, last_trt, email) 
                        SELECT employee_name, status_new, template, turn_around_time_set, tpa  
                        FROM importclaims WHERE id = $name1 ";

                $query = Yii::$app->db->createCommand($sql)->execute();

                echo '<div class="alert alert-success"> Pendings Availble </div>';

            }
            else
            {
                echo '<div class="alert alert-success"> No Pendings Availble </div>';
            }
            // return $this->redirect(['index']);


        }

but this executing only those TRT equal to today's date, but i need to check every TRT date which is lesser than equal todays date.

simply, Insert data those TRT date less and equal to today's date

Nodemon
  • 1,036
  • 2
  • 25
  • 47

3 Answers3

1

Finally i found the answer,

$today = strtotime(date('Y-m-d'));
$dt1 = ArrayHelper::map(Importclaims::find()->all(),'id','turn_around_time_set');
 foreach ($dt1 as $key => $value) 
        {
            $trt = print_r($value, true);
            $new = strtotime($trt);
if($new <= $today)
            {
                $sql = "INSERT INTO importpending (claimer_name, status, template, last_trt, email) 
                        SELECT employee_name, status_new, template, turn_around_time_set, tpa  
                        FROM importclaims WHERE id = $name1 ";

                $query = Yii::$app->db->createCommand($sql)->execute();

                echo '<div class="alert alert-success"> Pendings Availble </div>';

            }
Nodemon
  • 1,036
  • 2
  • 25
  • 47
0

You should not use where clauses in your insert queries - but if you have to, you would have to write your query like that:

"INSERT INTO importpending (claimer_name, status, template, last_trt, email)
                        (SELECT employee_name, status_new, template,  
                        turn_around_time_set, tpa  
                        FROM importclaims
                        WHERE id = $name1 AND TRT < '".$today."')";

Please note that you will have to change your date format to make this work. More information about date formats in mysql you can find here

Community
  • 1
  • 1
Coder55
  • 559
  • 5
  • 17
0

You can do it in single SQL Query, see below example:

INSERT INTO importpending (`claimer_name`, `status`, `template`, `last_trt`, `email`) 
SELECT  
    `employee_name`, `status_new`, `template`, `turn_around_time_set`, `tpa`  
FROM importclaims 
WHERE turn_around_time <= NOW()
kamal pal
  • 4,187
  • 5
  • 25
  • 40