Solved

foreach checkboxes checked

Posted on 2011-03-10
4
683 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

911 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now