أحببت أن أشارككم بهذه المشاركة ..
كود PHP:
<?php
$connect = mysql_connect('localhost', 'root', '');
mysql_select_db('database');
if ($_POST['action'] == 'delete')
{
$in = $_POST['id'];
if ($in[0] == '')
{
echo '<div>you did not select any posts to delete..</div>';
}
else
{
$in = implode(', ', $in);
//echo "<div>you select: <strong>$in</strong></div>";
if (mysql_query("delete from table where id in ( $in )"))
{
echo 'the posts has bin delete..';
}
else
{
echo 'cannot delete the posts..';
}
}
}
else
{
$result = mysql_query("select * from table");
if (mysql_num_rows($result) == 0)
{
echo '<div>there is no posts..</div>';
}
else
{
echo '<script type="text/javascript">
function checkAll(){
var inputs = document.getElementsByTagName(\'input\');
for (var i = 0; i < inputs.length; i++){
if (inputs[i].type == \'checkbox\' && inputs[i].name == \'id[]\'){
inputs[i].checked = true;
}
continue;
}
}
function uncheckAll(){
var inputs = document.getElementsByTagName(\'input\');
for (var i = 0; i < inputs.length; i++){
if (inputs[i].type == \'checkbox\' && inputs[i].name == \'id[]\'){
inputs[i].checked = false;
}
continue;
}
}
</script>
<div>select the posts that you want to delete..</div>
<form action="" method="post">
<input type="hidden" name="action" value="delete" />';
while ($row = mysql_fetch_array($result))
{
$id = $row['id'];
$topic = $row['topic'];
echo "<div><input type=\"checkbox\" name=\"id[]\" value=\"$id\" /> $topic</div>";
}
echo '<div><input type="button" value="check all" onclick="javascript:checkAll();" /> <input type="button" value="uncheck all" onclick="javascript:uncheckAll();" /> <input type="submit" value="delete" /></div>
</form>';
}
}
mysql_close($connect);
?>