Re: passing data in a form
| From: | Rosen | Date: | Sun, 20 Apr 2003 12:11:16 +0000 |
| Subject: | Re: passing data in a form | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-144532@lists.php.net to get a copy of this message | ||
Yes, you can do it.
Something like this:
$br=0;
$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++;
$name="zone_checked_$br";
$display_block .="<input type='checkbox' name=\"$name\"
value=\"$zone\">$zone<br>";
}
then send parameter $br to processing form and then get it with cycle
for ($i=1;$i<=$br;$i++)
{
$name="zone_checked_$i";
$zone_selected = $_POST[$name];
}
I hope this do help you
Rosen
"Mailing" <mailing@jduncan.co.uk> wrote in message
news:Email.zU1FahkvbK5@jduncan.co.uk...
> Can someone explain this to me. In newbie terms please - so that I
understand it rather than just paste it in. Thanks
>
> This is my code:
> <snip>
> $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'];
> $display_block .="<input type='checkbox'
> name=\"zone_selected\"
value=\"$zone\">$zone<br>";
> }
> <end snip>
> This displays the zones that I have available as checkboxes in my form.
> If I select one checkbox all works as expected
> using :
>
> $zone_selected = $_POST[zone_selected];
>
> However, if I select 2 or more checkboxes, I only get the results of the
last option selected.
>
> How can I add a "while there is data in $zone_selected repeat them on the
page...." sort of thing.
>
> Many thanks fr any help
> Jim
>
>