具有多个条件的多个查询将结果存储在一行中

时间:2017-01-05 15:08:59

标签: php mysql arrays

我根据日志时间的计算开展项目。

我的问题是如何从多个查询中获取一行以将最终编译结果存储在一行中?

我的BDD表:

Capture1

Capture2

我的PHP脚本:

$total_heures = array();
$total_pausette_ress1 = array();
$total_brief_r_ress1 = array();
$total_dej_r_ress1 = array();
//ALL DETAILS
$requete333="SELECT SUM(TIMESTAMPDIFF(SECOND, `in_time`,`out_time` ))  AS total_hours, in_time, out_time, pause_type, user_id
FROM rpconnect_attendance
WHERE status = 'pending'
AND MONTH(in_time) = MONTH(CURDATE()) GROUP BY DAYOFMONTH(`in_time`), user_id";
    $resultat1333= mysqli_query($con,$requete333);
                      $i = 0; 
                      while($rs3 = mysqli_fetch_assoc($resultat1333)){
                            $bgi = ++$i % 2 ? '#f3f3f3':'#ffffff'; 

                      $total_heures[$i] = $rs3;
                      }

$total_pausette1 = "SELECT SUM(TIMESTAMPDIFF(SECOND, `in_time`,`out_time` )) AS total_pausette1 , in_time, out_time, pause_type, user_id
                                                    FROM rpconnect_attendance
                                                    WHERE status = 'pending'
                                                    AND pause_type = 'pausette'
                                                    AND MONTH(`in_time`) = MONTH(CURDATE()) GROUP BY DAYOFMONTH(`in_time`), user_id";
                $total_pausette_res1 = mysqli_query($con,$total_pausette1);
                  $j = 0;
                 while($total_pausette_r1 = mysqli_fetch_assoc($total_pausette_res1)){
                     $bgj = ++$j % 2 ? '#f3f3f3':'#ffffff';
                 $total_pausette_ress1[$j] = $total_pausette_r1;            

                 } 

$total_brief1 = "SELECT SUM(TIMESTAMPDIFF(SECOND, `in_time`,`out_time` ))  AS total_brief1, in_time, out_time, pause_type, user_id
                                                    FROM rpconnect_attendance
                                                    WHERE status = 'pending'
                                                    AND pause_type = 'pausebrief'
                                                    AND MONTH(in_time) = MONTH(CURDATE()) GROUP BY DAYOFMONTH(`in_time`), user_id";
                $total_brief_res1 = mysqli_query($con,$total_brief1);
                $x =0;
                while($total_brief_r1 = mysqli_fetch_array($total_brief_res1)){
                    $bgx = ++$x % 2 ? '#f3f3f3':'#ffffff';

                $total_brief_r_ress1[$x] = $total_brief_r1;                   

                }



$total_dej1 = "SELECT SUM(TIMESTAMPDIFF(SECOND, `in_time`,`out_time` ))  AS total_dej1, in_time, out_time, pause_type
                                FROM rpconnect_attendance
                                WHERE status = 'pending'
                                AND pause_type = 'pausedej'
                                AND MONTH(in_time) = MONTH(CURDATE()) GROUP BY DAYOFMONTH(`in_time`), user_id";
                $total_dej_res1 = mysqli_query($con,$total_dej1);
                $p = 0;
                while($total_dej_r1 = mysqli_fetch_array($total_dej_res1)){
                    $bgp = ++$p % 2 ? '#f3f3f3':'#ffffff';
                $total_dej_r_ress1[$p] = $total_dej_r1;

                }


foreach($total_heures as $t) {            
foreach($total_pausette_ress1 as $p) {
foreach($total_brief_r_ress1 as $b) {
    foreach($total_dej_r_ress1 as $d) {

   $temp_total = $t['total_hours'];
   $today = $t['in_time'];
   $user = $t['user_id'];
   $date_mois = date("Y-m-d", strtotime("$today"));

   $temp_pause = $p['total_pausette1'];
   $temp_brief = $b['total_brief1'];
   $temp_dej = $d['total_dej1'];
   $inject_hour = "INSERT INTO `rpconnect_stockage`
                (`user_id`, `date`, `total_time`, `pause_time`, `brief_time`, `dej_time`)
                VALUES ('$user','$date_mois','$temp_total', '$temp_pause', '$temp_brief', '$temp_dej')" ;
                        $rassemblement = mysqli_query($con,$inject_hour);
}
}
}
}

提前感谢您对我提出的问题的兴趣

0 个答案:

没有答案