背景
我有一个脚本,用于轮换员工分享停车场的分配。一切正常,即我能够从mysql数据库中检索员工列表到数组中,按字母顺序排序并在旋转的时尚表中填充表格。一切都好。
我想要实现的目标
我希望能够做的是,如果我更改月份,即从8月到9月,则从当月开始的轮换将从上个月的剩余时间继续。现在使用当前脚本,它将在给定月份内完美旋转,但如果我输入新月,则重置旋转。
我一直在思考如何能够继续轮换,但却在努力解决这个问题。
个人想法......
一个想法也许是我应该在mysqldb中标记旋转中的最后一个人然后在下个月继续从被标记的人开始轮换?
以下是当前的工作脚本
<?php
$weeks = array();
$month = 'Aug';
$year = '2015';
$date = new DateTime("first Monday of $month $year");
$thisMonth = $date->format('m');
while ($date->format('m') === $thisMonth) {
array_push($weeks, $date->format('d-m-Y'));
$date->modify('next Monday');
}
//print_r($weeks);
$weeks_count = count($weeks);
//echo $weeks_count;
//=========================================
include_once 'connect.php';
dbconnect("roster");
$NoOfRows = 8;
$NoOfWeeks = $weeks_count;
$totalLots = $NoOfRows * $NoOfWeeks;
$dataArr = array();
//fetch all persons
$query = "SELECT * FROM carpark ORDER BY First_Name";
$result = mysqli_query($conn, $query) or die("error getting data");
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
array_push($dataArr, $row['First_Name']);
}
$noOfPersons = count($dataArr);
//Create a new array with filling all lots
while ($noOfPersons < $totalLots) {
$dataArr = array_merge($dataArr, $dataArr);
$noOfPersons = count($dataArr);
}
$weekArr = array_chunk($dataArr , $NoOfRows);
//print the table
echo "<table border=1>";
for ($row = 0; $row < $NoOfRows; $row++) {
if ($row == 0) {
echo "<tr><th></th>";
for ($col = 1; $col <= $NoOfWeeks; $col++) {
$weeks_loop = $col-1;
echo "<th>Week $col<br>$weeks[$weeks_loop]</th>";
}
echo "</tr>";
}
for ($col = 0; $col < $NoOfWeeks; $col++) {
if ($col == 0) {
echo "<tr><td><strong>Bay $row</strong></td>";
}
echo "<td>";
echo $weekArr[$col][$row];
echo "</td>";
}
echo "</tr>";
}
echo "</table>";
?>
输出屏幕截图
如果我改变下一个月会发生什么,轮换应该从Claire,Duncan,Gabriel等开始。