Re: for loop and array

From: Date: Wed, 25 Sep 2002 06:31:31 +0000
Subject: Re: for loop and array
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-117524@lists.php.net to get a copy of this message
I think you add square brackets: <input name='labtype[]' type='checkbox' value='Hepb_ag'> so you'd have an array with a numeric key (0-n) and the value of the key would be the value of the input. or perhaps you'd prefer <input name='labtype[Hepb_ag]' type='checkbox' value='1'> in this case the key of the array would be 'Hepb_ag', and the value would be true (1). In both cases, I don't think anything is set for false values... ie, if 3 out of 5 checkboxes are ticked, the array will have 3 items, not 5. Justin on 25/09/02 4:16 PM, Chris Grigor (chris@calibre.co.za) wrote: > Good Morning all > > I need some help as to how to print this array, its input name is labtype > and they all have differnet values. > > Amylase<input name='labtype' type='checkbox' > value='Amylase'> > <td align=right>Cholesterol<input name='labtype' type='checkbox' > value='Cholesterol'></td></tr> > <tr><td align=right>CMV Ab IgM/G<input name='labtype' > type='checkbox' > value='CMV'></td> > <td align=right>GLUCOSE - Fasting<input name='labtype' > type='checkbox' > value='GLU_Fast'></td></tr> > <tr><td align=right>GLUCOSE - Random<input name='labtype' > type='checkbox' > value='GLU_Rand'></td> > <td align=right>Hepatitus B S Ag<input name='labtype' > type='checkbox' > value='Hepb_ag'></td></tr> > > On the page I created if the person selects any of these then it should > submit it as name=labtype and value="whatever is selected" > > this works. > > Now upon getting this info onto my php script how would I say something like > > for each item in the array labtype, print its value? > > Any help would be really appreciated, I have had a look at a for loop trying > to use the following > > for ($a=1; $a<50; $a++) { > echo "<br>$labtype[$a]"; > } > > but this is not working for me. Can anyone direct me in the right way ??? >

« previous php.general (#117524) next »