Jump to content


Photo

PHP code and checkboxes.


  • Please log in to reply
1 reply to this topic

#1 crash21

crash21
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 02 September 2006 - 11:53 PM

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?

#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 03 September 2006 - 01:53 AM

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:
<input type="checkbox" name="row[]" value="$rowID" />

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":
<?php
// reject has been clicked
$rows = $_POST['row'];
foreach ($rows as $row) {
  // now you deal with each one individually and reject them:
  // reject $row;
}
?>

hope this helps
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users