Solved

foreach checkboxes checked

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Output in PHP throwing alignment of data off issue 12 42
Magento: different theme for Pc and for mobile devices 4 29
Wordpress Security 29 46
check mysql insert 12 26
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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…

789 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