我的更新表单有问题。按下更新按钮时,它始终更新表格的顶行而不是您要更新的表格。使用jquery ajax sendForm函数在按下update时对div进行更新。它在添加该功能之前有效。 尝试更新其他行也会将更改还原到顶行。
`
foreach ($pdo->query('
SELECT *
from SubPlaceViewer;
')as $row) {
echo "<tr>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['placeName']."</td>";
echo "<td>".$row['realName']."</td>";
echo "<td>".$row['entID']."</td>";
echo "<td>".$row['firstName']." ".$row['lastName']."</td>";
echo "<td>".$row['length']."</td>";
echo "<td>".$row['height']."</td>";
echo "<td>".$row['fakesnow']."</td>";
?>
<td>/* Changed form-id. Still doesnt d */
<form id="changeSubPlace<?php echo $row['name']; ?>">
<input type="hidden" name="name" value="<?php echo $row['name']; ?>">
<select name='entID'>
<?php
foreach ($pdo->query('SELECT * FROM Ent') as $row) {
echo '<option value="'.$row['entID'].'">';
echo $row['firstName']." ".$row['lastName'];
echo "</option>";
}
?>
</select>
<button type="button" onclick="SendForm('subplace', 'subplace', 'changeSubPlace<?php echo $row['name']; ?>');">update</button>
</form>
</td>
</tr>
<?php
}
?>
</table>
</div>
<?php
if(isset($_POST['name'])){
$sql = "call _newResponsabilitySubPlace (:_entID,:_name)";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(":_entID", $_POST['entID'], PDO::PARAM_INT);
$stmt->bindParam(":_name", $_POST['name'], PDO::PARAM_INT);
$stmt->execute();
}
?>`
功能:
function SendForm(page, go, form) {
$.ajax({
url : 'includes/'+page+'.php', // där formulär inmatning hanteras.
type: 'POST',
data: $("#"+form).serialize(), // serializes formulärets element.
success: function(data){
MakeRequest(go); // den div som ska laddas efter körning.
}
});
}