【问题标题】:How to i fetch all the date in to the select data table [closed]如何将所有日期提取到选择数据表中[关闭]
【发布时间】:2019-08-21 09:53:55
【问题描述】:

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

$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;

    }

我也得到了当月的所有日期。但我可以附加到当前表中的日期。帮助我很受用。

我想获取表格中设置的剩余日期。

【问题讨论】:

    标签: php mysql


    【解决方案1】:

    考虑以下几点:

    <?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>';}
        }
    
    
    ?>
    

    输出

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

    【讨论】:

    • 这可能对我有帮助。我会尝试是一个。谢谢您的关注
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多