PDA

View Full Version : Group Bool data and store to db


michelle
09-10-2002, 05:50 PM
Hi all,

I've some question about storage of my checkboxes. My checkboxes will return true if its check. I var_dump the result as follow:



array(25) {
["id"]=>
string(5) "ffdgd"
["password"]=>
string(6) "hhhhhh"
["_password_confirm"]=>
string(6) "hhhhhh"
["phone"]=>
string(0) "52446434634"
["food2"]=>
bool(true)
["ent2"]=>
bool(true)
["famil"]=>
bool(true)
["trav2"]=>
bool(true)
}



As you notice the food2, ent2, famil and trav2 are just some of those chkboxes which are being chk. Have anyone had any idea how I could store them? I'm actually looking forward to store them in my db field as set, but in what could I group every chkboxes together so that I could insert them into one field?

Thanks in advance for responding. I have been in this for many days and really don't have any idea. Thanks

firepages
09-11-2002, 02:57 AM
serialize is your friend...

<?
/*to serialize*/
$store_this=serialize($HTTP_POST_VARS['checkbox_field']);
/*
assume you stored the above in a DB , and now have fetched that row from the DB.
*/
$array=unserialize($row['fieldname']);
var_dump($array);
?>



you can serialize() whole arrays , multi-dimensional arrays, even complete objects & then recreate them instantly with unserialize(), well worth playing with.