Php 如何将所有日期提取到select数据表中
我将所有日期提取到my report表中。但它仅包含time\u in和time\u out记录的日期。我希望将所有日期提取到表中,time\u in和time\u out以及total hours列为空。如何解决此问题Php 如何将所有日期提取到select数据表中,php,mysql,Php,Mysql,我将所有日期提取到my report表中。但它仅包含time\u in和time\u out记录的日期。我希望将所有日期提取到表中,time\u in和time\u out以及total hours列为空。如何解决此问题 $query = " SELECT * FROM month_data INNER JOIN nonacadamic ON month_data.Emp_no = nonacadamic.emp_id WHERE nonacadamic.emp
$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;
}
我还得到了当前月份的所有日期。但是我可以附加到当前表中的日期。我非常感谢您的帮助
我想把设置好的剩余日期提取到表中。
考虑以下几点:
<?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