Welcome Guest, Not a member yet? Register   Sign In
How to delete multiple data
#1

[eluser]Cadu de Castro Alves[/eluser]
Hello people.

I'd like to know how to delete multiple data using only one call. I need to delete multiple selected grid rows, but I don't know how to do.

Thanks in advance.
#2

[eluser]xwero[/eluser]
Quote:delete from table where id in (1,2,3,4)
I think this is what you are looking for. if the rows are connected to other tables just reuse the id to delete the data.
#3

[eluser]Cadu de Castro Alves[/eluser]
xwero,

I'm able to use SQL queries. What I want to know is how can I do it calling a URL.
For example: To delete only one record, I call http://mysite.com/item/delete/123 where item is my item name, delete is the method and 123 is the item id.

So, how to delete multiple items if I can't use multiple item ids in the URL? Or can I use?

Thanks in advance!
#4

[eluser]xwero[/eluser]
I'm sorry.

I think the most common way is to post the multiple ids. As you wrote you have a grid with on each row a checkbox and one delete button i guess.
#5

[eluser]rogierb[/eluser]
you could do something like:

call http://mysite.com/item/delete_multiple/1...-5-6-7-8-9

And then use Split() to separate the id's
#6

[eluser]Cadu de Castro Alves[/eluser]
@xwero: Each row has only a checkbox. I'm using JS (in fact, I'm using ExtJS) to get all selected rows. So, I click on the delete button and call an AJAX request to do the action.

@rogierb: Is it the better way to delete multiple data? I'm thinking about pass the ID using an array? Do you know if it works?

Thanks in advance!
#7

[eluser]Craig A Rodway[/eluser]
[quote author="Cadu de Castro Alves" date="1201557458"]@xwero: Each row has only a checkbox. I'm using JS (in fact, I'm using ExtJS) to get all selected rows. So, I click on the delete button and call an AJAX request to do the action.[/quote]

Then what xwero originally posted is correct - the form data submitted via ExtJS should include all the IDs that you want to delete - providing you set your form and checkbox names/values up correctly.
#8

[eluser]Edemilson Lima[/eluser]
Instead of passing them by the URL, you can post a form. Example:

Code:
<form action="/controler/function" method="post" onSubmit="return false">
&lt;input type="checkbox" name="id[1]" value="1"&gt;Item 1<br>
&lt;input type="checkbox" name="id[2]" value="2"&gt;Item 2<br>
&lt;input type="checkbox" name="id[3]" value="3"&gt;Item 3<br>
&lt;input type="checkbox" name="id[4]" value="4"&gt;Item 4<br>
&lt;input type="checkbox" name="id[5]" value="5"&gt;Item 5<br>
&lt;input type="submit" value="Submit" onClick="ajax_submit(this.form)"&gt;
&lt;/form&gt;

Where "ajax_submit()" will be your current AJAX function to submit forms. May you need to put the URL on it.
At your PHP script you will get it as an array:

Code:
$ids=$this->input->post('id');
foreach($ids as $item) {
  echo $item,'<br>';
}
#9

[eluser]rogierb[/eluser]
Quote:@rogierb: Is it the better way to delete multiple data? I’m thinking about pass the ID using an array? Do you know if it works?

I don't know if it is a better way but we do it using jQuery. Using javascript we read what to delete and pass the ids to the delete-page. We use a 'checksum' to determine if the ids passed are valid.

We get something like: http://oursite.com/delete_multiple/ckeck...-4-6-7-8-9

That does the trick for us.




Theme © iAndrew 2016 - Forum software by © MyBB