You are here: Re: multiple checkboxes « All PHP « IT news, forums, messages
Re: multiple checkboxes

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 &#x2192;"/>
</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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация