我正在尝试通过php生成一个表,该表将根据该ID下的数据库中的内容提供满足可选择选项的下拉框。这个问题是,我还想根据用户输入到下拉框中的内容来更新表格,而且我对此没有好运。
表生成完美无缺。
echo "<form id='RemarketingRollCall' method='POST'>";
echo "<tr>";
echo "<td name='ID[]' contenteditable='false' align='center' width='11%'>" . $row['ID'] . "</td>";
echo "<td name='name[]' contenteditable='false' align='center' width='11%'>" . $row['Name'] . "</td>";
echo "<td name='job[]' contenteditable='false' align='center' width='11%'>
<select name='Name'>
<option>Remarketing</option>
<option>IOS</option>
<option>Computers</option>
</select></td>";
if ( strcmp( $row['Monday'], 'Attended' ) == 0 ){
echo "<td name='monday[]' contenteditable='false' align='center' width='11%'>
<select name='Monday'>
<option>Attended</option>
<option>Absent</option>
</select></td>";
} else if ( strcmp( $row['Monday'], 'Absent' ) == 0 ){
echo "<td name='monday[]' contenteditable='false' align='center' width='11%'>
<select name='Monday'>
<option>Absent</option>
<option>Attended</option>
</select></td>";
} else {
echo "<td name='monday[]' contenteditable='false' align='center' width='11%'>
<select name='Monday'>
<option> </option>
<option>Absent</option>
<option>Attended</option>
</select></td>";
}
if ( strcmp( $row['Tuesday'], 'Attended' ) == 0 ){
echo "<td name='tuesday[]' contenteditable='false' align='center' width='11%'>
<select name='Tuesday'>
<option>Attended</option>
<option>Absent</option>
</select></td>";
} else if ( strcmp( $row['Tuesday'], 'Absent' ) == 0 ){
echo "<td name='tuesday[]' contenteditable='false' align='center' width='11%'>
<select name='Tuesday'>
<option>Absent</option>
<option>Attended</option>
</select></td>";
} else {
echo "<td name='tuesday[]' contenteditable='false' align='center' width='11%'>
<select name='Tuesday'>
<option> </option>
<option>Absent</option>
<option>Attended</option>
</select></td>";
}
if ( strcmp( $row['Wednesday'], 'Attended' ) == 0 ){
echo "<td name='wednesday[]' contenteditable='false' align='center' width='11%'>
<select name='Wednesday'>
<option>Attended</option>
<option>Absent</option>
</select></td>";
} else if ( strcmp( $row['Wednesday'], 'Absent' ) == 0 ){
echo "<td name='wednesday[]' contenteditable='false' align='center' width='11%'>
<select name='Wednesday'>
<option>Absent</option>
<option>Attended</option>
</select></td>";
} else {
echo "<td name='wednesday[]' contenteditable='false' align='center' width='11%'>
<select name='Wednesday'>
<option> </option>
<option>Absent</option>
<option>Attended</option>
</select></td>";
}
if ( strcmp( $row['Thursday'], 'Attended' ) == 0 ){
echo "<td name='thursday[]' contenteditable='false' align='center' width='11%'>
<select name='Thursday'>
<option>Attended</option>
<option>Absent</option>
</select></td>";
} else if ( strcmp( $row['Thursday'], 'Absent' ) == 0 ){
echo "<td name='thursday[]' contenteditable='false' align='center' width='11%'>
<select name='Thursday'>
<option>Absent</option>
<option>Attended</option>
</select></td>";
} else {
echo "<td name='thursday[]' contenteditable='false' align='center' width='11%'>
<select name='Thursday'>
<option> </option>
<option>Absent</option>
<option>Attended</option>
</select></td>";
}
if ( strcmp( $row['Friday'], 'Attended' ) == 0 ){
echo "<td name='friday[]' contenteditable='false' align='center' width='11%'>
<select name='Friday'>
<option>Attended</option>
<option>Absent</option>
</select></td>";
} else if ( strcmp( $row['Friday'], 'Absent' ) == 0 ){
echo "<td name='friday[]' contenteditable='false' align='center' width='11%'>
<select name='Friday'>
<option>Absent</option>
<option>Attended</option>
</select></td>";
} else {
echo "<td name='friday[]' contenteditable='false' align='center' width='11%'>
<select name='Friday'>
<option> </option>
<option>Absent</option>
<option>Attended</option>
</select></td>";
}
echo "<td name='week[]' contenteditable='false' align='center' width='11%'>" . $row['Week'] . "</td>";
echo "</tr>";
echo "</form>";
这是假设要更新sql表的部分。
foreach($_POST['ID'] as $id){
echo $id . ' ';
foreach($_POST['name'] as $Name){
echo $Name . ' ';
foreach($_POST['job'] as $Job){
foreach($_POST['monday'] as $Monday){
foreach($_POST['tuesday'] as $Tuesday){
foreach($_POST['wednesday'] as $Wednesday){
foreach($_POST['thursday'] as $Thursday){
foreach($_POST['friday'] as $Friday){
$sql = "UPDATE Employee SET `Name`=$Name, `Job`=$Job, `Monday`=$Monday, `Tuesday`=$Tuesday, `Wednesday`=$Wednesday, `Thursday`=$Thursday, `Friday`=$Friday WHERE `ID`=$id";
if ( !mysqli_query( $con, $sql ) )
{
die( 'Error: ' . mysqli_error( $con ) );
}
mysqli_close( $con );
?>
<script type="text/javascript">
self.parent.location.href = "/index.php";
</script>
<?php
}
}
}
}
}
}
}
}
}
编辑 - 忘了提出我的问题。抱歉。 我目前的代码中出错了什么?我无法弄清楚为什么这不起作用。