RE: [PHP] Re: passing data in a form
| From: | John W. Holmes | Date: | Sun, 20 Apr 2003 15:11:59 +0000 |
| Subject: | RE: [PHP] Re: passing data in a form | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-144541@lists.php.net to get a copy of this message | ||
> Yes, you can do it.
> Something like this:
You're basically just creating an array with the following code, so why
not just do it that way...
> //$br=0;
Don't worry about $br, you don't need it.
> $sql ="SELECT DISTINCT zone FROM targetlist where valid_user =
> '$valid_user' ";
> $result = @mysql_query($sql) or die(mysql_error());
> $num = @mysql_num_rows($result);
>
> while ($row =mysql_fetch_array($result)){
> $zone = $row['zone'];
> //$br++;
Don't need to increment $br.
> $name="zone_checked_$br";
> $display_block .="<input type='checkbox' name=\"$name\"
> value=\"$zone\">$zone<br>";
Name your input element with [], as someone else mentioned. You can even
make whatever $zone you selected the key, instead of starting at zero.
$display_block .="<input type=\"checkbox\" name=\"zone[$zone]\"
value=\"$zone\">$zone<br>";
If there's a possibility $zone could have double quotes (") within it,
then you'll need to run htmlentities() on it before sticking it in the
value attribute of your input element.
>
> }
>
> then send parameter $br to processing form and then get it with cycle
With this method, you don't have to worry about sending $br to the next
page, either...
> for ($i=1;$i<=$br;$i++)
> {
> $name="zone_checked_$i";
>
> $zone_selected = $_POST[$name];
>
> }
All of the above could be replaced with:
Foreach($_POST['zone'] as $value)
{ echo "You chose $value"; }
Hope that helps...
---John W. Holmes...
PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/