DarkChocolate Reborn
DarkChocolate Reborn

Reputation: 43

How do I call a variable to be stored in my database

This is the function. The idea is to store $late in the 'late' column on my database. But I cant seem to store it. I tried using a static $shiftstart="08:30:00" and tried commenting the db->select()function upto foreach (){} loop AND it works, it stores the $late on my database. But if the db->select()function and foreach(){}loop, it doesnt work. What could I be doing wrong? What should I do to store it properly while using the db->select()function query?

function update_dtr($rs) {
    foreach ($rs as $key => $value) {
      $db=new Database();
     $db->connect();
        
     $alterin= date('H:i:s', strtotime($value['alterIN']));
     $db->select(array('myilogin_46.DATE_TIME_RECORDS'),'SHIFT_START'
        ,"ID = '".$value['dtrID']."' and ID_EMP = '".$value['empID']."' and R_STATUS='A'");

         foreach ($db->getResult() as $key => $value) {
             $shiftstart1 = $value['SHIFT_START'];
             $shiftstart= date('H:i:s',strtotime($shiftstart1));
            
         }

                //$shiftstart= date('H:i:s',strtotime("08:30:00"));
            
                var_dump($shiftstart);
                var_dump($alterin> $shiftstart);
                    var_dump($alterin);
                //working condition 
                if($shiftstart >= $alterin){
                $late= date('H:i:s',strtotime('00:00:00'));
                }else{
                    
                    $late1=strtotime($alterin)-strtotime($shiftstart);// int
                $late= gmdate('H:i:s', ($late1));
                
                }

                // $db->disconnect();
                    echo $late;
                    echo date('H:i:s',strtotime($late));
                    var_dump(date('H:i:s',strtotime($late)));
            
                    // $db1 = new Database();
                    // $db1->connect();

                // //$laters="00:00:00";

                 $db->update_imp('myilogin_46.DATE_TIME_RECORDS',array(
                     'date_in'=>date('Y-m-d',strtotime($value['alterIN']))
                     ,'time_in_info'=>'ALTERED IN'
                     ,'time_out_info'=>'ALTERED OUT'
                     ,'late'=> $late
                     ,'time_in'=>date('H:i',strtotime($value['alterIN']))
                     ,'time_out'=>date('H:i',strtotime($value['alterOUT']))
                     ,'date_out'=>date('Y-m-d',strtotime($value['alterOUT']))
                 ),"id = '".$value['dtrID']."' and id_emp = '".$value['empID']."' 
                    and R_STATUS = 'A'");
                    
           $db->disconnect();
    }
}

Upvotes: 0

Views: 34

Answers (1)

DarkChocolate Reborn
DarkChocolate Reborn

Reputation: 43

My bad on this one, beginners mistake, turns out the 2nd FOREACH:

foreach ($db->getResult() as $key => $value) {
         $shiftstart1 = $value['SHIFT_START'];
         $shiftstart= date('H:i:s',strtotime($shiftstart1));
        
     } 

Should be coded like this(change $VALUE TO $VAL) to avoid system conflict.

foreach ($db->getResult() as $key => $val) {


         $shiftstart1 = $val['SHIFT_START'];
         $shiftstart= date('H:i:s',strtotime($shiftstart1));
        
     }

Upvotes: 1

Related Questions