Re: Anyone Up?

From: Date: Fri, 01 Feb 2002 09:52:36 +0000
Subject: Re: Anyone Up?
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-83093@lists.php.net to get a copy of this message
On Thu, 2002-01-31 at 23:37, jtjohnston wrote: > Niklas, > Bingo. I wondered if it was somehting like that? Same thing in JS more or > less. > Thanks, > John eval() will work here, but it's overkill--it's a very expensive operation. You should avoid it whenever you can. A better way is to put everything into an array: In the form generation bit, use something like this: echo '<input type="checkbox" name="check[' . $mydata->id . ']" value="' . $mydata->yourname . '"> Then when the form is submitted, you'll have an array named $check containing any checked values. Here's a quick test script (change $_POST to $HTTP_POST_VARS if your PHP is older than 4.1.0): ---test.php--- <form action="test.php" method="post"> Billy Bob: <input type="checkbox" name="check[Billy Bob]" value="BB"><br /> Betty Sue: <input type="checkbox" name="check[Betty Sue]" value="BS"><br /> Jethro: <input type="checkbox" name="check[Jethro]" value="JETHRO"><br /> <input type="submit"> </form> <pre> <?php error_reporting(E_ALL); if (isset($_POST['check'])) { foreach ($_POST['check'] as $name) { echo "Checked: $name\n"; } } ?> </pre> ---test.php--- The wrapping probably will get screwed up in the above, but the idea should be clear. Hope this helps, Torben > > eval() is your solution. > > > > for ($i = 1; $i <= $NMax; $i++) > > { > > $variable = "\$Check$i"; > > eval("\$string = \"$variable\";"); > > echo $string."<br>"; > > } > > > > Niklas > > > > -----Original Message----- > > From: jtjohnston [mailto:taylorjo@collegesherbrooke.qc.ca] > > Sent: 1. helmikuuta 2002 9:16 > > To: php-general@lists.php.net > > Subject: [PHP] Anyone Up? > > > > Anyone Awake? Up? > > > > I'm using 12 checkboxes > > > > <INPUT TYPE="checkbox" NAME="Check1" VALUE="Your > > Name"> > > > > dynamically generated by mysql. Each has an id as primary index so I do > > this: > > > > <INPUT TYPE=\"checkbox\" NAME=\"Check".$mydata->id."\" > > VALUE=\"".$mydata->yourname."\"> > > > > When I submit, I want to echo to see if anyone clicked on them. But I > > can't get my variable right to find $check1 through $check12. How do I > > express in a for loop. $Check.$i does not work of course! > > > > for ($i = 1; $i <= $NMax; $i++) > > { > > echo $Check.$i"<br>"; > > } > > > > :) Help > > > > -- > > 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 > > > -- > 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 > -- Torben Wilson <torben@php.net> http://www.thebuttlesschaps.com http://www.hybrid17.com http://www.inflatableeye.com +1.604.709.0506

« previous php.general (#83093) next »