Jump to content

Archived

This topic is now archived and is closed to further replies.

crash21

PHP code and checkboxes.

Recommended Posts

Hello,

I have made a page in which I load a mysql query.
The results from this query load in page and see some results.
In this page I must allow or reject a site.
The results are like this:

ID    Site                              URL                            Email
1    something                      something.com            something@something.com
2    somewhere                    somewhere.com            something@somewhere.com


Ok, now next to email I have one checkbox and at belwo of page two butons one Allow and one Reject.
The problem is how to make it to connect checkboxes with button and all chackboxes which I click and after click allow, allow site and all sites which check reject, reject them.
I haven't got an idea...
I have done it but with another way which allow me to allow and reject one site every time (writhing the id in a textfield and press either allo or reject...) but this way is not very efficient...
Can you please help me?

Share this post


Link to post
Share on other sites
basically, the best way is to handle all your checkboxes as a big array. name them all the same with "[]" after them. for instance, you may have this at the end of each row:
[code]
<input type="checkbox" name="row[]" value="$rowID" />
[/code]

where $rowID is the id of the URL or email you are reviewing. then, when you check all the ones you want and submit the form, the $_POST['row'] variable then holds all of them as an array. you can loop through them all at that point and either accept or reject them. so, let's say you click "reject":
[code]
<?php
// reject has been clicked
$rows = $_POST['row'];
foreach ($rows as $row) {
  // now you deal with each one individually and reject them:
  // reject $row;
}
?>
[/code]

hope this helps

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.