你可以用表格来做:
//main.php
Recent Posts | ||
<?php echo $row['field1']; ?> | <?php echo $row['field2']; ?> |
//delete.php:
if(isset($_POST['delete_id'] && !empty($_POST['delete_id']))) {
$delete_id = mysql_real_escape_string($_POST['delete_id']);
mysql_query("DELETE FROM KeepScores WHERE `id`=".$delete_id);
header('Location: main.php');
}
或者你可以使用jQuery和AJAX:
//main.php
Recent Posts | ||
<?php echo $row['field1']; ?> | <?php echo $row['field2']; ?> | Delete |
$(document).ready(function(){
$('.del_btn').click(function(){
var del_id = $(this).attr('rel');
$.post('delete.php', {delete_id:del_id}, function(data) {
if(data == 'true') {
$('#'+del_id).remove();
} else {
alert('Could not delete!');
}
});
});
});
//delete.php
if(isset($_POST['delete_id'] && !empty($_POST['delete_id']))) {
$delete_id = mysql_real_escape_string($_POST['delete_id']);
$result = mysql_query("DELETE FROM KeepScores WHERE `id`=".$delete_id);
if($result !== false) {
echo 'true';
}
}
这一切都是未经测试的,确定需要对您的具体项目进行一些调整,但我认为您明白这一点,我希望它有所帮助.
下次,如果您询问有关数据库的内容,请发布您的架构.