You are here: Re: how to add delete buttons per subitem in 1 form in an easy way « PHP Programming Language « IT news, forums, messages
Re: how to add delete buttons per subitem in 1 form in an easy way

Posted by Rik on 12/13/06 18:59

wim taerwe wrote:
> Hello,
>
> I am looking for an easy way to have a delete button per subitem in 1
> form.
>
> For example : a book can have many authors and when I edit the book
> details I want to have a list of the authors each with a separate
> delete-submitbutton next to it. Now I have the problem that I cannot
> know which exact author I want to delete when I click the delete
> button next to it.
>
> I could name every delete button differently like
> "delete_author1","delete_author2",... but what is the easiest way to
> process this after the submit.

I normally use in a list:
- a button on the top names 'delete[mass]'
- checkboxes in front named id[<id_number]
- a button named delete[<id_number>] in the row

when the logic is calles for (pseudoscript to illustrate):

if(isset($_POST['delete'])){
$ids = array();
if(isset($_POST['delete']['mass'])){
$ids = array_map('intval',array_keys($_POST['id']));
} else {
$ids[] = intval(reset(array_keys($_POST['delete'])));
}
if(!empty($ids)){
$query = 'DELETE FROM table WHERE id = '.implode(', or id =
',$ids);
mysql_query($query);
}
}

So, a 'mass' button to delete all selected, and a numbered button to delete
a specific one.
The trick is naming the inputs with the [], which will automatically create
an array for you in php's $_POST.
--
Rik Wasmus

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация