Re: Displaying array of elements problem

From: Date: Thu, 24 Jan 2002 09:03:29 +0000
Subject: Re: Displaying array of elements problem
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-81841@lists.php.net to get a copy of this message
first, set up the array something like: $artist("Bon Jovi","N\'Sync","Boyzone","Britney Spears","Jethro Tull", "Crosby\, Stills & Nash"); // note escape slash before single quote and comma I think they'll be needed, but maybe not. then set up your checkbox array something like: <?php print <form action=test.php method=GET> for ($i=0;$i<=count($artist)-1;$i++) { print "<input type=checkbox name=artist[$i] value=\'$artist[$i]\'>$artist[$i]"; // The escape slashes are important here } print <input type=submit name=submit> print </form> if (isset($submit)) { for ($i=0;$i<=count($artist)-1;$i++) { if (isset($artist[$i])) print $artist[$i]; if (isset($artist[$i])) $number=$number+1; } print $number; if ($number=="0") die ("go back and select something"); / / or do something else here. } The above is untested especially the array set up, but the rest should give you a hint on how to do what you want. Hugh ----- Original Message ----- From: "Michael P. Carel" <mikecarel@teamglac.com> To: "php" <php-general@lists.php.net> Sent: Wednesday, January 23, 2002 11:31 PM Subject: [PHP] Displaying array of elements problem > Hi there, > > I have another problem out here. Im using the for loop to display an array > of element in the checkbox form. > My problem is how could i set the this if to an error message if their are a > NULL selection. By default this will display blank for no selection which i > whant to be avoided. I dont know what particular variable should i declare > if there are NULL selection so that i can incorporate that in an error > script. > > Please help me. > > > Sample script: > > <? > // check for $submit > if (!$submit) > { > // and display form > ?> > <form action="test.php" method="GET"> for > <input type="checkbox" name="artist[]" value="Bon Jovi">Bon > Jovi > <input type="checkbox" name="artist[]" > value="N'Sync">N'Sync > <input type="checkbox" name="artist[]" > value="Boyzone">Boyzone > <input type="checkbox" name="artist[]" value="Britney > Spears">Britney Spears > <input type="checkbox" name="artist[]" value="Jethro > Tull">Jethro Tull > <input type="checkbox" name="artist[]" value="Crosby, Stills & > Nash">Crosby, Stills & Nash > <br> > <input type="submit" name="submit" value="Select"> > </form> > <? > } > // or display the selected artists > else > { > > ?> > <b>And here are your selections:</b> > <br> > <? > -----error script line should be here---------- > > > for($count = 0; $count < sizeof($artist); $count++) > { > echo "<i>$artist[$count]</i><br>"; > } > > } > ?> > > > > > Regards, > Mike > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#81841) next »