Anda dapat melakukannya dengan formulir:
//main.php
<?php $result = mysql_query("SELECT * FROM KeepScores"); ?>
<table>
<tr>
<td>Recent Posts</td>
</tr>
<?php while($row = mysql_fetch_array($result)) : ?>
<tr>
<td><?php echo $row['field1']; ?></td>
<td><?php echo $row['field2']; ?></td>
<!-- and so on -->
<td>
<form action="delete.php" method="post">
<input type="hidden" name="delete_id" value="<?php echo $row['id']; ?>" />
<input type="submit" value="Delete" />
</form>
</td>
</tr>
<?php endwhile; ?>
</table>
//delete.php:
<?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');
}
Atau Anda dapat melakukannya dengan jQuery dan AJAX:
//main.php
<?php $result = mysql_query("SELECT * FROM KeepScores"); ?>
<table>
<tr>
<td>Recent Posts</td>
</tr>
<?php while($row = mysql_fetch_array($result)) : ?>
<tr id="<?php echo $row['id']; ?>">
<td><?php echo $row['field1']; ?></td>
<td><?php echo $row['field2']; ?></td>
<!-- and so on -->
<td>
<button class="del_btn" rel="<?php echo $row['id']; ?>">Delete</button>
</td>
</tr>
<?php endwhile; ?>
</table>
<script>
$(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!');
}
});
});
});
</script>
//delete.php
<?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';
}
}
Semuanya belum teruji dan tentu memerlukan beberapa penyesuaian untuk proyek spesifik Anda, tetapi saya rasa Anda sudah mengerti dan saya harap ini membantu.
Lain kali, harap posting skema Anda jika Anda menanyakan hal-hal tentang database.