RE: [PHP] *OK, more eval for today

From: Date: Wed, 18 Dec 2002 19:37:42 +0000
Subject: RE: [PHP] *OK, more eval for today
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-128766@lists.php.net to get a copy of this message
> Okay, wait. > How? > > say, I have a field of checkboxes in 3 columns and 6 rows. I need at least > one checked. > At the moment every checkbox has the name of kind: q3_4_1 , where 4 stands > for row and 1 for column. Now, how do I name them and loop through them? > Plus, if $HTTP_POST_VAR["q3_4_1"] wasn't checked at all, the value is not > passed over, right? So I get... null, I believe. So with my eval I first > do > if(isset()) and then go on. How would I I behave in your case? > Please, John, if you could be even more specific?.... > > Sweating Alex Well, you could do it exactly the same way, but with arrays. The same way that you name it "q3_4_1", you'd name your elements exactly like "q3[4][1]", which will give you a $HTTP_POST_VARS['q3'][4][1] variable. So you just loop through that array and see what's set and what isn't. It depends on what you do if the are set or not, but you can do something like this. I'm going to use $_POST for simplicity. //$_POST['q3']['row']['column'] (reference) for($row = 0;$row < 6; $row++) { for($col = 0; $col < 3; $col++) { if(isset($_POST['q3'][$row][$col])) { echo "Checkbox row: $row, column: $col was checked"; } else { echo "Checkbox row: $row, column: $col was not checked"; } } } Untesteed, but that should work. ---John Holmes...

« previous php.general (#128766) next »