我有我的PHP,打印出一堆mysql
數據庫的行。它看起來像這樣:php而關閉另一個ID的行
如果我點擊close ticket
頂行,它會永遠關閉最後一個行ID,因爲它是最後一個ID放排,我不知道這有什麼錯我的代碼。那就是:
<?php
$sql = "SELECT id,name,server,issue,title,open FROM tickets WHERE open='1' ORDER by time";
$result = $configconn->query($sql);
\t \t \t \t \t \t \t \t
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$ticketid = $row["id"];
$ticketopen = $row["open"];
$ticketserver = $row["server"];
$ticketissue = $row["issue"];
$tickettitle = $row["title"];
$ticketname = $row["name"];
if($ticketopen == 1) {
$open = '<span class="label label-success label-mini">Open ID:'.$ticketid.'</span>';
} else {
$open = '<span class="label label-danger label-mini">Closed ID:'.$ticketid.'</span>';
}
echo ' <tr>
<td>'.$open.'</td>
<td class="hidden-phone">'.$ticketissue.'</td>
<td>'.$tickettitle.' </td>
<td><span class="label label-info label-mini">'.$ticketserver.'</span></td>
<td>'.$ticketname.' </td>
<form action="openedtickets.php" method="POST">
<td> \t \t \t \t \t \t \t
<button class="btn btn-danger btn-xs" type="submit" name="submit" value="Register">Close Ticket</button> \t \t \t \t \t \t \t
</td>
</form>
</tr>';
\t \t \t \t \t \t \t
}
} else {
Echo '<center><div class="alert alert-success">There are no open Tickets!</div></center>';
}
?>
<?php
if(isset($_POST['submit'])){
if($_SESSION['power'] >= 1){
$sql = "UPDATE tickets SET open='0' WHERE id='$ticketid'";
if (mysqli_query($configconn, $sql)) {
$sollved = $_SESSION['ticketssolved'] + 1; \t
$sql2 = "UPDATE users SET ticketssolved='$sollved' WHERE user='$user'"; \t
mysqli_query($configconn, $sql2);
\t \t \t \t \t \t \t \t \t \t \t
$closedby = $_SESSION['username']; \t
$sql3 = "UPDATE tickets SET closedticket='$closedby' WHERE id='$ticketid'"; \t
mysqli_query($configconn, $sql3);
header("Location: openedtickets.php");
} else {
Echo '<center><div class="alert alert-danger">Ticket ID:'.$ticketid.' Failed to Close!</div></center>';
\t \t \t \t \t \t \t \t \t \t \t
}
} else {
Echo '<center><div class="alert alert-danger">Sorry you need to be Trial Mod or Higher!</div></center>';
}
\t \t \t \t \t \t \t \t \t
}
?>
查看所提供的代碼,它看起來並不像你通過票號在所有當你點擊關閉票... –
我認爲它獲取最後一張票的ID,因爲當我點擊第一個按鈕上的關閉票時,它總是關閉行中的最後一張票,而不是我點擊的那張。 – David