Welcome Guest, Not a member yet? Register   Sign In
How can we delete multiple by checkbox
#2

[eluser]Unknown[/eluser]
I’m working on some cms tool to make posts on site I used a lot of cms like Joomla, WordPress and Textpattern. Now I want to make something like that, of course not even similar to that but just for my personal use and fun.

2 things to do:

1. Option to select all checkboxes. I like something like in joomla in top there is checkbox with titles when u select it all checkbox are selected and if u uncheck it all is unchecked
2. When I press delete button all checkboxes that I select are deleted from database or moved to some other category like trash which is nice because u can in that way return some posts that u delete by mistake or some other reason

Here is my code that bothers me becouse checkboxes don't work

Help with Code Tags
php Syntax (Toggle Plain Text)

1.
<?php
2.
include ('conf/config.php');
3.
include('conf/opendb.php');
4.
$sql="SELECT id, title, author, DATE_FORMAT(date, '%M %d, %Y') as sd FROM $tbl_name";
5.
$result=mysql_query($sql);
6.

7.
$count=mysql_num_rows($result);
8.

9.
?>
10.
<table border="0" cellspacing="0" cellpadding="0">
11.
<tr>
12.
<td>&lt;form name="form1" method="post" action=""&gt;
13.
<table border="0" cellpadding="0" cellspacing="0" class="adminlist">
14.
<tr id="top">
15.
<th width="5" align="center">Id</th>
16.
<th width="5" align="center">#</th>
17.
<th>Title</th>
18.
<th width="200" align="center">Author</th>
19.
<th width="100" align="center">Date</th>
20.
<th width="80" align="center">Delete</th>
21.
<th width="20" align="center">Edit</th>
22.
</tr>
23.
&lt;?php
24.
while($rows = mysql_fetch_array($result)){
25.
?&gt;
26.
<tr>
27.
<td width="5" align="center">&lt;? echo $rows['id']; ?&gt;</td>
28.
<td width="5" align="center">&lt;input name="checkbox[]" type="checkbox" id="checkbox[]" value="&lt;? echo $rows['id']; ?&gt;"&gt;&lt;/td>
29.
<td>&lt;? echo $rows['title']; ?&gt;</td>
30.
<td width="200" align="center">&lt;? echo $rows['author']; ?&gt;</td>
31.
<td width="100" align="center">&lt;? echo $rows['sd']; ?&gt;</td>
32.
<td width="80" align="center" id="trash"><a href="delete_news.php?id=&lt;? echo $rows['id']; ?&gt;">Delete</a></td>
33.
<td width="20" align="center" id="edit"><a href="edit_news.php?id=&lt;? echo $rows['id']; ?&gt;">Edit</a></td>
34.
&lt;?php
35.
}
36.
?&gt;
37.
<tr>
38.
<td colspan="7" align="center">&lt;input name="delete" type="submit" id="delete" value="Delete"&gt;&lt;/td>
39.
</tr>
40.
&lt;?
41.
// Check if delete button active, start this
42.
if($delete){
43.
for($i=0;$i<$count;$i++){
44.
$del_id = $checkbox[$i];
45.
$sql = "DELETE FROM $tbl_name WHERE id='$del_id'";
46.
$result = mysql_query($sql);
47.
}
48.

49.
// if successful redirect to delete_multiple.php
50.
if($result){
51.
echo "&lt;meta http-equiv=\"refresh\" content=\"0;URL=post_manage.php\"&gt;";
52.
}
53.
}
54.
mysql_close();
55.
?&gt;
56.
</table>
57.
&lt;/form&gt;
58.
</td>
59.
</tr>
60.
</table>


Messages In This Thread
How can we delete multiple by checkbox - by El Forum - 09-11-2009, 07:01 AM
How can we delete multiple by checkbox - by El Forum - 09-11-2009, 07:19 AM
How can we delete multiple by checkbox - by El Forum - 09-11-2009, 07:46 AM
How can we delete multiple by checkbox - by El Forum - 09-11-2009, 07:48 AM



Theme © iAndrew 2016 - Forum software by © MyBB