0
我查找了一個答案,但似乎找不到一個答案。能夠從循環中刪除SQL的某個結果
我希望能夠從數據庫中刪除特定的查詢。
我如何從表單中刪除特定的表單並將其發佈到要刪除的SQL語句中?
這是我目前的select語句。
<?
if (isset($_POST['submit']))
{
echo "Hello!";
$selectOption = $_POST['info'];
$query = "SELECT * FROM `REQUESTS` ORDER BY $selectOption";
echo $query;
$result = $db->query($query);
if ($result == FALSE) {
die ("could not execute statement $query<br />");
}
else
echo "<form action='' method='post'>";
echo "<table>";
while($row=$result->fetchRow()){
if ($row['status'] == 0) {
$type="rejected";
}
else if ($row['status'] == 1){
$type="pending";
}
else if ($row['status'] == 2){
$type="accepted";
}
echo "<tr id=".$type."><td>" . $row['requestid'] . "</td>";
echo "<td>" . $row['booking_type'] . "</td>";
echo "<td>" . $row['userid'] . "</td>";
echo "<td>" . $row['moduleid'] . "</td>";
echo "<td>" . $row['no_rooms'] . "</td>";
echo "<td>" . $row['park'] . "</td>";
echo "<td>" . $row['semester'] . "</td>";
echo "<td>" . $row['day'] . "</td>";
echo "<td>" . $row['start_time'] . "</td>";
echo "<td>" . $row['end_time'] . "</td>";
echo "<td>" . $row['length'] . "</td>";
echo "<td>" . $row['students'] . "</td>";
echo "<td>" . $row['priority'] . "</td>";
echo "<td>" . $row['comments'] . "</td>";
echo "<td>" . $row['status'] . "</td>";
// <td class="'.(($row['status'] == 2) ? 'status-rejected' : 'status-accepted'). '">'.$row['status'].'</td>';
echo "<td>".$stats."</td>";*/
echo "<td>" . $row['round'] . "</td>";
echo "<td>" . $row['date_submitted'] . "</td>";
}
echo "</tr>";
echo "</table>";
echo "</form>";
}
echo "</tr>";
echo "</table>";
您需要使用包含該行ID的隱藏元素將表格添加到每個表格行。點擊後,您可以使用該行的ID來調用刪除查詢。此外,你正在混合和混雜術語相當糟糕。你想刪除一個特定的*行*,而不是一個while循環的結果。 –
或者你可以用ajax來做。另外,出於安全原因,這部分'die(「無法執行語句$ query
」)'應該從你的代碼中移除。 –