从 2 个数组填充的下拉列表中获取表单值时出现问题
Having problems getting form values from dropdowns populated from 2 arrays
员工数组包含具有唯一 ID 的员工姓名。
花名册数组使用唯一 ID 来确定当天有哪些员工。
我正在尝试在按下提交时发送更新的 'roster' 数组,但我似乎无法从表单中获取任何值。我正在做一些愚蠢的事情,但我看不到树木的阿甘。
$roster array
Array
(
[0] => Array
(
[0] => date
[1] => id[s]
)
[1] => Array
(
[0] => 25/12/2017-31/12/2017
[1] => 1
[2] => 2
)
[2] => Array
(
[0] => 01/01/2018-07/01/2018
[1] => 2
[2] => 3
)
[3] => Array
(
[0] => 08/01/2018-14/01/2018
[1] => 2
[2] => 1
)
[4] => Array
(
[0] => 15/01/2018-21/01/2018
[1] => 8
[2] => 1
[3] => 3
)
[5] => Array
(
[0] => 22/01/2018-28/01/2018
[1] => 2
)
[6] => Array
(
[0] => 29/01/2018-04/02/2018
[1] => 2
[2] => 1
)
)
$staff array
Array
(
[0] => Array
(
[Team] => RED
[Name] => Person A
[ID] => 001
)
[1] => Array
(
[Team] => BLUE
[Name] => Person B
[ID] => 002
)
[2] => Array
(
[Team] => RED
[Name] => Person C
[ID] => 003
)
[3] => Array
(
[Team] => BLUE
[Name] => Person D
[ID] => 004
)
[4] => Array
(
[Team] => RED
[Name] => Person E
[ID] => 005
)
[5] => Array
(
[Team] => Test Group
[Name] => Test Person
[ID] => 006
)
)
<?php
$teams=array();
$last = count($staff) - 1;
foreach ($staff as $i => $row)
{
$isFirst = ($i == 0);
$isLast = ($i == $last);
array_push($teams,$row['Team']); //push all teams into on array to find the number of teams in total
}
echo "<pre>";
print_r($roster);
print_r($staff);
print_r($teams);
echo "</pre>";
$uniqueteams=array_unique($teams);
echo '<form method="post" action="save.php" id="rosterform">';
echo '<table border="1"><tr id="heading">';
//print the team names
print "<td>Week Date</td>";
foreach ($uniqueteams as $i)
{
print "<td>".$i."</td>".PHP_EOL;
}
echo "</tr>";
foreach (range(0, 52) as $wknumber) {
echo "<tr>";
echo "<td>";
echo "week ".$wknumber;
echo "</td>";
foreach ($uniqueteams as $i)
{
echo "<td><div><select name=\"rostered\">".PHP_EOL;
foreach ($staff as $j => $row){
if ($row['Team']==$i){
echo '<option value="'.$row['ID'].'">'.$row['Name'].'</option>'.PHP_EOL;
}
}
echo "</select></div></td>".PHP_EOL;
}
}
echo '</table>';
//save the roster.csv file back
echo '<input type="submit" name="save" value="save">';
echo '</form>';
?>
</body>
</html>
foreach ($uniqueteams as $i)
{
echo "<td><div><select name='rostered".$wknumber."[]'>".PHP_EOL;
foreach ($staff as $j => $row){
if ($row['Team']==$i){
echo '<option value="'.$row['ID'].'">'.$row['Name'].'</option>'.PHP_EOL;
}
}
echo "</select></div></td>".PHP_EOL;
}
员工数组包含具有唯一 ID 的员工姓名。 花名册数组使用唯一 ID 来确定当天有哪些员工。
我正在尝试在按下提交时发送更新的 'roster' 数组,但我似乎无法从表单中获取任何值。我正在做一些愚蠢的事情,但我看不到树木的阿甘。
$roster array
Array
(
[0] => Array
(
[0] => date
[1] => id[s]
)
[1] => Array
(
[0] => 25/12/2017-31/12/2017
[1] => 1
[2] => 2
)
[2] => Array
(
[0] => 01/01/2018-07/01/2018
[1] => 2
[2] => 3
)
[3] => Array
(
[0] => 08/01/2018-14/01/2018
[1] => 2
[2] => 1
)
[4] => Array
(
[0] => 15/01/2018-21/01/2018
[1] => 8
[2] => 1
[3] => 3
)
[5] => Array
(
[0] => 22/01/2018-28/01/2018
[1] => 2
)
[6] => Array
(
[0] => 29/01/2018-04/02/2018
[1] => 2
[2] => 1
)
)
$staff array
Array
(
[0] => Array
(
[Team] => RED
[Name] => Person A
[ID] => 001
)
[1] => Array
(
[Team] => BLUE
[Name] => Person B
[ID] => 002
)
[2] => Array
(
[Team] => RED
[Name] => Person C
[ID] => 003
)
[3] => Array
(
[Team] => BLUE
[Name] => Person D
[ID] => 004
)
[4] => Array
(
[Team] => RED
[Name] => Person E
[ID] => 005
)
[5] => Array
(
[Team] => Test Group
[Name] => Test Person
[ID] => 006
)
)
<?php
$teams=array();
$last = count($staff) - 1;
foreach ($staff as $i => $row)
{
$isFirst = ($i == 0);
$isLast = ($i == $last);
array_push($teams,$row['Team']); //push all teams into on array to find the number of teams in total
}
echo "<pre>";
print_r($roster);
print_r($staff);
print_r($teams);
echo "</pre>";
$uniqueteams=array_unique($teams);
echo '<form method="post" action="save.php" id="rosterform">';
echo '<table border="1"><tr id="heading">';
//print the team names
print "<td>Week Date</td>";
foreach ($uniqueteams as $i)
{
print "<td>".$i."</td>".PHP_EOL;
}
echo "</tr>";
foreach (range(0, 52) as $wknumber) {
echo "<tr>";
echo "<td>";
echo "week ".$wknumber;
echo "</td>";
foreach ($uniqueteams as $i)
{
echo "<td><div><select name=\"rostered\">".PHP_EOL;
foreach ($staff as $j => $row){
if ($row['Team']==$i){
echo '<option value="'.$row['ID'].'">'.$row['Name'].'</option>'.PHP_EOL;
}
}
echo "</select></div></td>".PHP_EOL;
}
}
echo '</table>';
//save the roster.csv file back
echo '<input type="submit" name="save" value="save">';
echo '</form>';
?>
</body>
</html>
foreach ($uniqueteams as $i)
{
echo "<td><div><select name='rostered".$wknumber."[]'>".PHP_EOL;
foreach ($staff as $j => $row){
if ($row['Team']==$i){
echo '<option value="'.$row['ID'].'">'.$row['Name'].'</option>'.PHP_EOL;
}
}
echo "</select></div></td>".PHP_EOL;
}