RE: [PHP] what am I doing wrong?

From: Date: Fri, 02 May 2003 19:32:10 +0000
Subject: RE: [PHP] what am I doing wrong?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-146185@lists.php.net to get a copy of this message
I always mess up calling a foreach on a _POST element that contains an array. Instead of messing with the [] placement (I can never remember if it would be $_POST[list_serv[]] or $_POST[list_serv][] or if I need {} in there somewhere) I just do this $list_serv = $_POST['list_serv']; foreach($list_serv as $list_serv_cd => $quantity) { It is kind of a cop out, but I am usually under a tight dealine and it gets the job done. > -----Original Message----- > From: Amanda McComb [mailto:amccomb@indiana.edu] > Sent: Friday, May 02, 2003 12:29 PM > To: Jennifer Goodie > Cc: php-general@lists.php.net > Subject: RE: [PHP] what am I doing wrong? > > > Yes! Sorry I didn't clarify that. I just ripped out the relevant > snippets. The last 'foreach' is what happens after a submit. > > On Fri, 2 May 2003, Jennifer Goodie wrote: > > > I think I posted too soon. Is the top chunk of code the form > and the bottom > > chunk the action? > > > > <?while ($search_result = > > > mysql_fetch_array($search_results)) {?> > > > > <INPUT > > > > TYPE="checkbox" > > > > NAME="list_serv[<? echo > > > > $search_result['list_serv_cd']; ?>]" > > > > SIZE="20" > > > > MAXLENGTH="50" > > > > VALUE="1"><? echo > > > > $search_result['list_serv_name'] ?> <BR> > > > > <? > > > > } > > > > > > > > foreach( $_POST['list_serv'] as $list_serv_cd => $quantity) { > > > > $quantity *= 1; // make it numeric > > > > if($quantity) { // if one exists > > > > echo $list_serv_cd; > > > > } > > > > }

« previous php.general (#146185) next »