Posted by Koncept on 12/03/06 16:57
In article <ekueq5$3qb$1@ss408.t-com.hr>, Gaga <rg2006@hotmail.com>
wrote:
> 1.) what is the best way to store multiple checkboxes into table. (e.g. if
> you 20 checkboxes there is no reason to make 20 table fields ? )
I would serialize an array and store the serialized string in the DB.
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<input type="checkbox" name="cb[1]" value="on" checked="checked" />
<input type="checkbox" name="cb[2]" value="on" checked="checked" />
<input type="checkbox" name="cb[3]" value="on" />
<input type="checkbox" name="cb[4]" value="on" checked="checked" />
<input type="checkbox" name="cb[5]" value="on" />
<input type="submit" value="submit →"/>
</form>
<?php
/*
POST data looks like this...
Array
(
[cb] => Array
(
[1] => on
[2] => on
[4] => on
)
)
*/
echo serialize( $_POST['cb'] );
// a:3:{i:1;s:2:"on";i:2;s:2:"on";i:4;s:2:"on";}
> 2.) How to pull this stored checkbox data so i can display which checkboxes
> are checked and which not ?
$cbdata = unserialize( $data ); // will give you the checked boxes as
an array.
--
Koncept <<
"The snake that cannot shed its skin perishes. So do the spirits who are
prevented from changing their opinions; they cease to be a spirit." -Nietzsche
[Back to original message]
|