我有一段代码,通过循环将数据库表中的每条记录输出到页面,我想添加一个按钮,当单击时关闭所选记录,就像一个忽略按钮,所以用户可以选择忽略那条特定记录。
我已设法让它隐藏记录但它只保持隐藏,直到刷新页面并且我希望它永远被忽略,所以我试图合并一个表来保存被忽略的记录,但它似乎没有工作。
它没有添加到表中,现在它也不会隐藏记录 - 任何想法?
以下是持有忽略按钮的代码部分
<div id="offerIgnore"><a href="#" onclick="ignore(ignore=offer&offer_id=<?php print "$offerid";?>);$('#offer<?php print "$offerid";?>').slideUp('slow', function(){});return false;"><img src="images/btnX.png" width="15" height="15" title="Ignore the offer" /></a></div><!---end offerIgnore--->
这是连接到php文件的代码
<script type="text/javascript">
function ignore(url) {
if (url == "") {
document.getElementById("txtHint").innerHTML = "";
return;
}
if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else { // code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET", "ignore.php?=" + url, true);
xmlhttp.send();
}
</script>
这是忽略php文件
<?php
session_start();
$id = "";
if ($_GET['id']) {
$id = $_GET['id'];
} else
if (isset($_SESSION['id'])) {
$id = $_SESSION['id'];
} else {
include_once "index.php";
exit();
}
include 'connect_to_mysql.php';
$ignore = $_GET['ignore'];
$offer_id = $_GET['offer_id'];
if ($ignore = 'offer') {
$sql_ignore_offer = mysql_query("INSERT INTO ignoreoffer (id, offer_id, date_ignored) VALUES ('$id', '$offer_id', now)");
} else {
$sql_ignore_survey = mysql_query("INSERT INTO ignoresurvey (id, offer_id, date_ignored) VALUES ('$id', '$offer_id', now)");
}
?>