Re: Checkboxes (LONG): Handling multiple rows

From: Date: Thu, 06 Jul 2000 02:34:56 +0000
Subject: Re: Checkboxes (LONG): Handling multiple rows
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-23651@lists.php.net to get a copy of this message
> If I check boxes 1, 3 & 5, I then get a response of > > 0 on > 1 on > 2 on This is because checkbox values will only be sent if they're checked, Unfortunately, this really complicates life for the sort of thing you're doing to keep it generic. Fortunately, PHP will combine values with indexes, allowing you to do something like this: <INPUT TYPE="Checkbox" NAME="check[1]" VALUE="foo"> <INPUT TYPE="Checkbox" NAME="check[2]" VALUE="bar"> <INPUT TYPE="Checkbox" NAME="check[3]" VALUE="baz"> <INPUT TYPE="Checkbox" NAME="check[4]" VALUE="quux"> or even <INPUT TYPE="Checkbox" NAME="check['foo']" VALUE="foo"> <INPUT TYPE="Checkbox" NAME="check['bar']" VALUE="bar"> What happens in this case is that the array elements selected will be defined: print_r($check) gives: Array [2] => bar [4] => quux ['bar'] => bar ) This means you could modify your script to do something like: echo "Processing " . count($check) . " rows"; while (list($row) = each($check)) { echo "Working on rows $row now"; }

« previous php.dev (#23651) next »