我正在制作一个功能,它在数据库中按行显示商店,每个商店后面都有一个按钮,每个商店前面都有一个复选框。我想找到另一种根据按下的按钮获取商店 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'\">and决定$selectedID = $_GET['givenID'];,但我宁愿使用一种在 URL 中不显示 ID 的方式。Post 似乎也是一个更好的选择,因为现在当我刷新页面时,由于 URL 中的 ID,它会再次执行查询。我怎样才能仍然获得 ID,但使用不同的方法。