<?php
session_start();
if(!$_SESSION['Admin']) {
header('Location: login.php'); exit();
}
?>
<!DOCTYPE HTML>
<html>
<head>
<title> ticketExpress | Admin </title>
<link rel='stylesheet' href='../assets/css/style.css'>
</head>
<body>
<div id='containerAdmin'>
<h1> <img class='logo' src='../assets/images/logo.png' width='200' height='43'> </h1> <a href='?logout' class='logout'> Logout </a>
<h3> Open Tickets </h3>
<hr />
<?php
require("../configuration/config.php");
$GetTickets = $con->query("SELECT * FROM tickets WHERE open='true'");
while($TicketInfo = $GetTickets->fetch_object()) {
$Subject = $TicketInfo->Subject;
echo "<div id='ticket'>".$Subject ."<a href='?delete=$TicketInfo->ID'><img style='float:right'src='../assets/images/delete.png' width='15px' height='15px'></a><a style='float:right; color:red; text-decoration:none; margin-right:10px;' href='?close=$TicketInfo->ID'> Close </a><font style='float:right; margin-right:10px; color:green;' id='responseMsg'> </font></div>";
}
if(isset($_GET['delete'])) {
$ID = $_GET['delete'];
echo "
<script type='text/javascript'>
var ajax = new XMLHttpRequest();
ajax.open('POST','delete.php', true);
ajax.setRequestHeader('Content-type','application/x-www-form-urlencoded');
ajax.onreadystatechange = function () {
if(ajax.readyState == 4 && ajax.status == 200) {
document.getElementById('responseMsg').innerHTML = ajax.responseText;
}
}
ajax.send('delete=$ID');
</script>
";
}
if(isset($_GET['logout'])) {
session_destroy();
header('Location: login.php');
}
if(isset($_GET['close'])) {
$ID = $_GET['close'];
echo "
<script type='text/javascript'>
var ajax = new XMLHttpRequest();
ajax.open('POST','close.php', true);
ajax.setRequestHeader('Content-type','application/x-www-form-urlencoded');
ajax.onreadystatechange = function () {
if(ajax.readyState == 4 && ajax.status == 200) {
document.getElementById('responseMsg').innerHTML = ajax.responseText;
}
}
ajax.send('close=$ID');
</script>
";
}
?>
<br />
</div>
</body>
</html>
私の問題は、削除をクリックするたびに、ページの最初のチケット (一番上のチケット) の横に ajax 応答が常に表示されることです。
たとえば、チケット 21 の横にある [閉じる] をクリックすると、ページの最初のチケット (チケット 1 など) の横に AJAX 応答の「Ticket Succesfully Closed」が常に表示されます。
ここにclose.phpがあります
<?php
require('../configuration/config.php');
if(isset($_POST['close'])) {
echo "Ticket Successfully Closed";
$TID = $_POST['close'];
$con->query("UPDATE tickets SET open='false' WHERE ID='$TID'");
}
そしてdelete.php
<?php
require('../configuration/config.php');
if(isset($_POST['delete'])) {
echo "Ticket Deleted";
$TID = $_POST['delete'];
$con->query("DELETE FROM tickets WHERE ID='$TID'");
}
いつものように、すべての回答は大歓迎です!前もって感謝します