Solved

foreach checkboxes checked

Posted on 2011-03-10
4
697 Views
Last Modified: 2012-05-11
in a form, how to

foreach checkboxes checked{
do something to row1
do something to row2
do something to row3
}
0
Comment
Question by:rgb192
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 4

Expert Comment

by:Doug Walton
ID: 35098666
Depending on how you're sending the form you might want something like this:
$checkbox1 = $_POST['name of checkbox1'];
if (isset($checkbox1))
{
  //do something for checkbox1
}

Open in new window

Then repeat for each box.

Is that what you're looking for?
0
 

Author Comment

by:rgb192
ID: 35099382
so would this work

if (isset($checkbox[]))
0
 
LVL 4

Accepted Solution

by:
Doug Walton earned 500 total points
ID: 35099606
Probably, if you want to store the checkbox values in an array you could do something like that.

$checkbox[0] = $_POST['input name of checkbox'];
$checkbox[1] = $_POST['input name of checkbox'];
...
for($i = 0; $i < count($checkbox); $i++)
{
  if (isset($checkbox[$i]))
  {
    //do something
  }
}

Open in new window


That would do that same thing for each checkbox.  If you want to do something different for each one, you could take it out of the for-loop.

Does that help?
0
 

Author Closing Comment

by:rgb192
ID: 35152616
thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question