How to delete multiple data |
[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.
[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.
[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!
[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.
[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
[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!
[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.
[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"> 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');
[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. |
Welcome Guest, Not a member yet? Register Sign In |