RE: checkbox arrays and validation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 05 October 2004 11:10, Angelo Zanetti wrote:

> Hi all,
> 
> this might be slightly off-topic in a way but Im looking for help not
> flaming. 
> 
> Ok I have a checkbox array that I populate from a DB using php:
> 
> while ($row = mysql_fetch_array($result))
>       echo("<input type=checkbox name=chkmodels[] value=" .
> $row['models_id'] . ">" . $row['models_type'] . "<br>");
> 
> So when I want to see each variable in the array I use:
> 
> 		foreach ($_POST['chkmodels'] as $c)
> 		{
> 			echo("<br> value: " . $c);
> 		}
> 
> this is fine.
> 
> but what I want to clarify is that if I change my PHP echo statement
> to: 
> 
> echo("<input type=checkbox name=chkmodels value=" . $row['models_id']
> . ">" . $row['models_type'] . "<br>");
> 
> basically without the [] then it is still recognised as an array. But
> when the array is passed back it is returned as a string separated by
> commas.

No, this is incorrect.  You will see only the last value selected, returned
as a simple scalar.  PHP doesn't do automatic array-ification of multiple
values -- that's why you need the [] in the name attribute.

Cheers!

Mike

---------------------------------------------------------------------
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Headingley Campus, LEEDS,  LS6 3QS,  United Kingdom
Email: m.ford@xxxxxxxxxxxxxx
Tel: +44 113 283 2600 extn 4730      Fax:  +44 113 283 3211 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux