You are here: Re: Iterate Through Values from All Checked Checkboxes « All PHP « IT news, forums, messages
Re: Iterate Through Values from All Checked Checkboxes

Posted by Tom on 12/11/06 18:27

On Mon, 11 Dec 2006 09:27:36 +0000, Geoff Berrow wrote...
>
>Message-ID: <1165824944.590557.238040@l12g2000cwl.googlegroups.com> from
>ameshkin contained the following:
>
>>On the second page, whch is the form actin, I simply want to iterate
>>through and pull which values are checked and run a sql command for
>>each value.
>>
>>I have no idea how to do this. I assume you willl have to use a for
>>each statement, but am having trouble programming this.
>
>There is a clever little trick you can use. For your checkboxes you
>give them a name like this
>
><input type='checkbox. name='del[]' value='3435'>
>
>where value is the id of the record you want to delete.
>
>By using the square brackets, all the values are conveniently placed in
>an array. So here is the foreach (untested):
>
>foreach($_POST['del'] as $value){
>//ideally do some checking that the value is one that the user is
>// allowed to delete here
>$sql="DELETE from table WHERE id=$value";
> if(mysql_query($sql)){
> echo "record id $value deleted<br>";
> }
> else{
> echo "Could not delete record id $value<br>";
> }
>}
>
>


Thanks for the tip Geoff. Nice having all the values in a tidy array.

Tom
--
Newsguy.com - Basic Accounts $39.95 / 12 months
http://newsguy.com/overview.htm

 

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

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