如何将所有日期提取到选择数据表中 [英] How to i fetch all the date in to the select data table

查看:51
本文介绍了如何将所有日期提取到选择数据表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将所有日期提取到我的报告表中.但它仅包含 time_in 和 time_out 记录日期.我想将所有日期提取到表中以及 time_in 和 time_out 以及总小时数列为空.我该如何解决这个问题.

$query = "SELECT * FROM 月份数据INNER JOIN 非学术性ON month_data.Emp_no = nonacadamic.emp_idWHERE nonacadamic.emp_id = '".$_POST["emp_id"]."'";$statement = $connect->prepare($query);if($statement->execute()){$result = $statement->fetchAll();$output = '

';$table='<table class="table table-bordered table-hover" id="table">';$table.='<tr><th>日期</th><th>Time In</th><th>Time Out</th><th>Total Hrs.</th></tr>';$emp_id = '';$emp_name = '';$Section = '';$指定 = '';$strat = date('Y-M-01');$end = date('Y-M-d');//指定开始日期.此日期可以是任何英文文本格式$date_from = $strat;$date_from = strtotime($date_from);//将日期转换为 UNIX 时间戳//指定结束日期.此日期可以是任何英文文本格式$date_to = $end;$date_to = strtotime($date_to);//将日期转换为 UNIX 时间戳//从开始日期到结束日期循环并输出其间的所有日期对于 ($i=$date_from; $i<=$date_to; $i+=86400) {echo date("Y-m-d D", $i).'<br/>';}foreach($result 作为 $row){$date = date_format( date_create($row['Date']), 'Y-m-d D') ;if($emp_id != sprintf('%05d',$row["emp_id"]) && $emp_name != $row['emp_name'] && $Section != ucwords($row['部分']) && $Designation !=ucwords($row['Designation']) ) {$output.='<div class="col-sm-4"><b>名称:</b><span>&nbsp;'.$row["emp_name"] .'</span></div><div class="col-sm-4">&nbsp;</div><div class="col-sm-4"><b>Emp.否:</b><span>&nbsp;'.sprintf('%05d',$row["emp_id"]) .'</span></div>';$output .= '<div class="col-sm-12">&nbsp;</div>';$output.='<div class="col-sm-4"><b>Division:</b><span>&nbsp;'.ucwords($row['Section']).'</span></div><div class="col-sm-4"><b>名称:</b><跨度>&nbsp;'.ucwords($row['Designation']).'</span></div><div class="col-sm-4"><b>期间:</b><span>&nbsp;'.$strat.'- '.$end.'</span></div>';$output .= '<div class="col-sm-12">&nbsp;</div>';}$emp_id= sprintf('%05d',$row["emp_id"]);$emp_name = $row['emp_name'];$Section = ucwords($row['Section']);$Designation = ucwords($row['Designation']);$table .='';$table .=''.date_format( date_create($row['Date']), 'Y-m-d D' ) .'</td>';$table .=''.$row['Time_in'] .'</td>';$table .=''.$row['Time_out'] .'</td>';$table .=''.$row['Total_hours'] .'</td>';$table .='</tr>';}$table .='';$output .= '</div>';回声 $output.$table;}

我也得到了当月的所有日期.但我可以附加到当前表中的日期.帮助我非常满意.

我想获取设置到表中的剩余日期.

解决方案

请考虑以下事项:

输出

1 是2 是3 是4 没有5 是6 没有7 是8 没有9 没有10 没有11 是12 没有

i fetch the the all the date in to the my report table.but it only contain the the time_in and time_out recorded date only.i want to fetch the all the date in to the table and time_in and time_out and total hours column as empty.how do i solve this question.

$query = "
    SELECT * FROM month_data
    INNER JOIN nonacadamic
    ON month_data.Emp_no = nonacadamic.emp_id 
    WHERE nonacadamic.emp_id = '".$_POST["emp_id"]."'";
    $statement = $connect->prepare($query);
    if($statement->execute())
    {   
        $result = $statement->fetchAll();
        $output = '<div class="row container">';

        $table='<table class="table table-bordered table-hover" id="table">';
        $table.='<tr><th>Date</th><th>Time In</th><th>Time Out</th><th>Total Hrs.</th></tr>';
        $emp_id = '';
        $emp_name = '';
        $Section = '';
        $Designation = '';
        $strat = date('Y-M-01');
        $end = date('Y-M-d');
        // Specify the start date. This date can be any English textual format  
        $date_from = $strat;   
        $date_from = strtotime($date_from); // Convert date to a UNIX timestamp  

        // Specify the end date. This date can be any English textual format  
        $date_to = $end;  
        $date_to = strtotime($date_to); // Convert date to a UNIX timestamp  

       // Loop from the start date to end date and output all dates inbetween  
        for ($i=$date_from; $i<=$date_to; $i+=86400) {  
              echo date("Y-m-d D", $i).'<br />';  
        }  
        foreach($result as $row)
        {
            $date = date_format( date_create($row['Date']), 'Y-m-d D' ) ; 


        if($emp_id != sprintf('%05d',$row["emp_id"]) && $emp_name != $row['emp_name'] && $Section != ucwords($row['Section']) && $Designation !=ucwords($row['Designation']) ) {

        $output.='<div class="col-sm-4"><b>Name   :</b><span> &nbsp;'. $row["emp_name"] .'</span></div>
                  <div class="col-sm-4">&nbsp;</div>
                  <div class="col-sm-4"><b>Emp. No    :</b><span> &nbsp;'. sprintf('%05d',$row["emp_id"]) .'</span></div>' ;
        $output .= '<div class="col-sm-12">&nbsp;</div>';
        $output.='<div class="col-sm-4"><b>Division    :</b><span> &nbsp;'. ucwords($row['Section']).'</span></div>
                  <div class="col-sm-4"><b>Designation    :</b> <span> &nbsp;'. ucwords($row['Designation']).'</span></div>
                  <div class="col-sm-4"><b>Period    :</b><span> &nbsp;'.$strat.' - '.$end.'</span></div>' ;
        $output .= '<div class="col-sm-12">&nbsp;</div>';

         }
        $emp_id= sprintf('%05d',$row["emp_id"]);
        $emp_name = $row['emp_name'];
        $Section = ucwords($row['Section']);
        $Designation = ucwords($row['Designation']);

         $table .='<tr class="info">';
         $table .='<td border border-dark>' . date_format( date_create($row['Date']), 'Y-m-d D' ) . '</td>';
         $table .='<td border border-dark>' . $row['Time_in'] . '</td>'; 
         $table .='<td border border-dark>' . $row['Time_out'] . '</td>';
         $table .='<td border border-dark>' . $row['Total_hours'] . '</td>';
         $table .='</tr>';
         }
          $table .='</table>';
          $output .= '</div>';
        echo $output.$table;

    }

i also getting the all the date in current month.but i can append to the date in the current table.help i much appiciated.

i want to fetch the remain date set into the table.

解决方案

Consider the following:

<?php

$array = array(1,2,3,5,7,11);

for($i=1;$i<=12;$i++){
  if(in_array($i,$array)){echo $i.' yes<br>';} else {echo $i.' no<br>';}
    }


?>

Outputs

1 yes
2 yes
3 yes
4 no
5 yes
6 no
7 yes
8 no
9 no
10 no
11 yes
12 no

这篇关于如何将所有日期提取到选择数据表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆