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

[eluser]Unknown[/eluser]
I don't know how to delete multiple by checkbox in codeigniter. How can i do?
for example i used to assign to url like exmple.com/index/delete/2,3,4 but i don't how can i do it?
#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>
#3

[eluser]NateL[/eluser]
[quote author="veasna" date="1252692082"]I don't know how to delete multiple by checkbox in codeigniter. How can i do?
for example i used to assign to url like exmple.com/index/delete/2,3,4 but i don't how can i do it?[/quote]

When you're creating your check boxes, you will create a checkbox array, like so:

Code:
&lt;form method="POST"&gt;
&lt;input type="checkbox" name="username[10]" value="Jon Doe" /&gt;
&lt;input type="checkbox" name="username[11]" value="Jane Doe" /&gt;
&lt;/form&gt;

This, being out put dynamically of course. In your database, you would have a table with an "id" field, which represents 10 and 11 in the above example.

When you click both of these buttons, and then click a "delete" button, this will post an associative array that will look like this:

Code:
array
      10 => string 'Jon Doe' (length=7)
      11 => string 'Jane Doe' (length=8)
Now you run a delete sql command inside a "foreach" loop that will remove the entry with that ID number.

This is quick and dirty...someone else may have a better suggestion, and I - for one - would definitely like to hear it, because I'm always looking for new ways to deal with checkboxes and radio buttons
#4

[eluser]NateL[/eluser]
@robison....

That's a mess of a code...and the reason why CodeIgniter exists....to avoid procedural jumbled up code like you've posted. Are you attempting to switch all of that over to CodeIgniter?




Theme © iAndrew 2016 - Forum software by © MyBB