我正在制作一项功能,以行的形式显示数据库中的商店,每个商店后面都有一个按钮,每个商店前面都有一个复选框。我想找到另一种方法,可以通过按下按钮来获取商店的ID。选择了按钮的商店将从数据库中删除。
$sql = "SELECT * FROM alb_locaties WHERE Verwijderd = '0'";
$result = $conn->query($sql);
if ($result->num_rows > 0){
echo "<form action='' method='get'>";
echo "<table id='MainTable'>
<tr>
<th></th>
<th>Shopnaam</th>
<th></th>
</tr>";
while ($row = $result->fetch_assoc()){
$ID = $row['I_id'];
echo "<tr>
<td><input type='checkbox' name='Shops[]' value='$ID'></td>
<td>$ID</td>
<input type='hidden' name='givenID' value='$ID'>
<td><a href=\"Reset_locatieshops.php?givenID='$ID'\"><input type='button' value='Verwijder'/></a></td>
</tr>";
}
echo "</table>";
echo "<input id='SelectionButton' type='submit' name='SelectionDelete' value='Verwijder selectie'/>";
echo "</form>";
}
if (isset($_GET['givenID'])){
$selectedID = $_GET['givenID'];
// FIRST DELETE
$sql = "SELECT * FROM alb_locaties INNER JOIN alb_afdelingen ON alb_locaties.I_id = alb_afdelingen.locaties WHERE alb_locaties.I_id = {$selectedID}";
现在,它由<a href=\"Reset_locatieshops.php?givenID='$ID'\">
和$selectedID = $_GET['givenID'];
决定,但是我宁愿使用一种在URL中不显示ID的方式。 Post似乎也是一个更好的选择,因为现在刷新页面时,由于URL中的ID,它再次执行查询。我仍然可以通过使用其他方法来获取ID。
没关系,我找到了。我将表单方法更改为发布,
我将<a href=\"Reset_locatieshops.php?givenID='$ID'\"><input type='button' value='Verwijder'/></a>
更改为<input type='submit' value='Verwijder' name='submit'>
。
此后,我使用$selectedID = $_POST['givenID'];
获取分配给<input type='hidden' name='givenID'
的ID