【发布时间】: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> '. $row["emp_name"] .'</span></div>
<div class="col-sm-4"> </div>
<div class="col-sm-4"><b>Emp. No :</b><span> '. sprintf('%05d',$row["emp_id"]) .'</span></div>' ;
$output .= '<div class="col-sm-12"> </div>';
$output.='<div class="col-sm-4"><b>Division :</b><span> '. ucwords($row['Section']).'</span></div>
<div class="col-sm-4"><b>Designation :</b> <span> '. ucwords($row['Designation']).'</span></div>
<div class="col-sm-4"><b>Period :</b><span> '.$strat.' - '.$end.'</span></div>' ;
$output .= '<div class="col-sm-12"> </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;
}
我也得到了当月的所有日期。但我可以附加到当前表中的日期。帮助我很受用。
【问题讨论】: