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:[EMAIL PROTECTED]]
> > Sent: 1. helmikuuta 2002 9:16
> > To: [EMAIL PROTECTED]
> > 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: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED] To
> > contact the list administrators, e-mail: [EMAIL PROTECTED]
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
> 
-- 
 Torben Wilson <[EMAIL PROTECTED]>
 http://www.thebuttlesschaps.com
 http://www.hybrid17.com
 http://www.inflatableeye.com
 +1.604.709.0506


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to