Re: [PHP] Handling Large Check Box Data

2006-05-18 Thread Richard Lynch
On Wed, May 17, 2006 1:21 pm, Rahul S. Johari wrote:
 I¹m a little confused as to what¹s the best way to handle this.
 I have a form which, apart from lots of other fields, has a set of 25
 ­ 30
 Check Boxes, each of which asks the user for some kind of information
 which
 the user can check or leave unchecked.
 The information each Check Box collects will also appear in the
 ³Listing²
 for users to view once the user has completed  submitted the form.
 Furthermore, there is an Advanced Search also available to users which
 will
 also provide the same 25 - 30 check boxes which define the search
 criteria.
 I¹m not sure what¹s the best, most efficient way to do this.

 The tedious way to do this is to make 30 fields in the mySQL database,
 and
 if the check box is checked, the data goes into the corresponding
 field...
 And similarly listing the data from the field if field is
 non-empty And
 similarly including each field in the Search options.

 I want suggestions for a better/faster way to do this. I did think
 about
 creating a single field and storing the data from each Œchecked¹ check
 box
 as comma separated values in the single field. I¹m not sure how to do
 that
 and if that¹s the best way But even if I can, I¹m not sure how to
 get
 the data to display separately out of that field in the Listings view
 and
 more importantly how to include that data in the Search options.

You could combine up to 32 bits into a 32-bit integer, and store the
choices as an 'int'

Something like:
?php
  $choices = array('box1', 'box2', 'whatever', 'moreboxes');
  $data = 0;
  foreach($choices as $choice){
if (isset($_POST['checkbox'][$choice]){
  $data = 2 * $data + 1;
}
else{
  $data = 2 * $data + 0;
}
  }
?

For nicer syntax, you could use those  and  operators for
bit-shifting instead of that goofy 2 * I used, because I was too
lazy to RTFM to lookup the syntax for  and 

But since you are right on the edge of needing over 32 bits, this is
probably not such a good idea...

You could also just use a string with the same basic framework:

$data = '';
foreach (...){
  if (isset(...)){
$data .= '1';
  }
  else{
$data .= '0';
  }
}

This is not real flexible when you add more choices, however.

Probably the CORRECT way to do it is to store the values in another
table, with an id field back to the current table.

This will provide the most flexibility in the long run, and probably
be more maintainable and have clearer code.

-- 
Like Music?
http://l-i-e.com/artists.htm

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



[PHP] Handling Large Check Box Data

2006-05-17 Thread Rahul S. Johari
Ave,

I¹m a little confused as to what¹s the best way to handle this.
I have a form which, apart from lots of other fields, has a set of 25 ­ 30
Check Boxes, each of which asks the user for some kind of information which
the user can check or leave unchecked.
The information each Check Box collects will also appear in the ³Listing²
for users to view once the user has completed  submitted the form.
Furthermore, there is an Advanced Search also available to users which will
also provide the same 25 - 30 check boxes which define the search criteria.
I¹m not sure what¹s the best, most efficient way to do this.

The tedious way to do this is to make 30 fields in the mySQL database, and
if the check box is checked, the data goes into the corresponding field...
And similarly listing the data from the field if field is non-empty And
similarly including each field in the Search options.

I want suggestions for a better/faster way to do this. I did think about
creating a single field and storing the data from each Œchecked¹ check box
as comma separated values in the single field. I¹m not sure how to do that
and if that¹s the best way But even if I can, I¹m not sure how to get
the data to display separately out of that field in the Listings view and
more importantly how to include that data in the Search options.

Any help would be appreciated.

Thanks, 

Rahul S. Johari
Coordinator, Internet  Administration
Informed Marketing Services Inc.
500 Federal Street, Suite 201
Troy NY 12180

Tel: (518) 687-6700 x154
Fax: (518) 687-6799
Email: [EMAIL PROTECTED]
http://www.informed-sources.com



Re: [PHP] Handling Large Check Box Data

2006-05-17 Thread Brad Bonkoski
Well, listing all the values in a comma separated list in the DB would 
be fairly simple to parse, check out:

http://www.php.net/manual/en/function.explode.php

As far as what is better depends on many things...
1). Maintaining the code, might be better to have each check box have 
its own field, will certainly cut down on development/debugging.
2). Performance...don't know if it is faster for PHP to parse through a 
comma separated list or parse through a larger DB record set. I guess if 
this is really important to you, you might want to attempt both ways to 
see on performance.


-Brad



Rahul S. Johari wrote:


Ave,

I¹m a little confused as to what¹s the best way to handle this.
I have a form which, apart from lots of other fields, has a set of 25 ­ 30
Check Boxes, each of which asks the user for some kind of information which
the user can check or leave unchecked.
The information each Check Box collects will also appear in the ³Listing²
for users to view once the user has completed  submitted the form.
Furthermore, there is an Advanced Search also available to users which will
also provide the same 25 - 30 check boxes which define the search criteria.
I¹m not sure what¹s the best, most efficient way to do this.

The tedious way to do this is to make 30 fields in the mySQL database, and
if the check box is checked, the data goes into the corresponding field...
And similarly listing the data from the field if field is non-empty And
similarly including each field in the Search options.

I want suggestions for a better/faster way to do this. I did think about
creating a single field and storing the data from each Œchecked¹ check box
as comma separated values in the single field. I¹m not sure how to do that
and if that¹s the best way But even if I can, I¹m not sure how to get
the data to display separately out of that field in the Listings view and
more importantly how to include that data in the Search options.

Any help would be appreciated.

Thanks, 


Rahul S. Johari
Coordinator, Internet  Administration
Informed Marketing Services Inc.
500 Federal Street, Suite 201
Troy NY 12180

Tel: (518) 687-6700 x154
Fax: (518) 687-6799
Email: [EMAIL PROTECTED]
http://www.informed-sources.com


 



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



Re: [PHP] Handling Large Check Box Data

2006-05-17 Thread Martin Alterisio

2006/5/17, Rahul S. Johari [EMAIL PROTECTED]:


Ave,

I¹m a little confused as to what¹s the best way to handle this.
I have a form which, apart from lots of other fields, has a set of 25 ­ 30
Check Boxes, each of which asks the user for some kind of information
which
the user can check or leave unchecked.
The information each Check Box collects will also appear in the ³Listing²
for users to view once the user has completed  submitted the form.
Furthermore, there is an Advanced Search also available to users which
will
also provide the same 25 - 30 check boxes which define the search
criteria.
I¹m not sure what¹s the best, most efficient way to do this.

The tedious way to do this is to make 30 fields in the mySQL database, and

if the check box is checked, the data goes into the corresponding field...
And similarly listing the data from the field if field is non-empty
And
similarly including each field in the Search options.

I want suggestions for a better/faster way to do this. I did think about
creating a single field and storing the data from each Œchecked¹ check box
as comma separated values in the single field. I¹m not sure how to do that

and if that¹s the best way But even if I can, I¹m not sure how to get
the data to display separately out of that field in the Listings view and
more importantly how to include that data in the Search options.

Any help would be appreciated.

Thanks,

Rahul S. Johari
Coordinator, Internet  Administration
Informed Marketing Services Inc.
500 Federal Street, Suite 201
Troy NY 12180

Tel: (518) 687-6700 x154
Fax: (518) 687-6799
Email: [EMAIL PROTECTED]
http://www.informed-sources.com





You should consider using MySQL special column type SET:

http://dev.mysql.com/doc/refman/5.1/en/set.html

Or encoding each checkbox status as a binary bit in an integer (which is
what MySQL does when using a SET column).


Re: [PHP] Handling Large Check Box Data

2006-05-17 Thread Jochem Maas

Martin Alterisio wrote:

2006/5/17, Rahul S. Johari [EMAIL PROTECTED]:



...







You should consider using MySQL special column type SET:

http://dev.mysql.com/doc/refman/5.1/en/set.html

Or encoding each checkbox status as a binary bit in an integer 


I was going to suggest this also- if nothing else it would be a cool
way to learn a bit (pun intended :-) about bitmask/bitfields/bitwise-operations.





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



Re: [PHP] Handling Large Check Box Data

2006-05-17 Thread Kevin Murphy
I did something similar recently. Basically I have one MySQL field to  
handle several dozen checkboxes, my situation though was where the  
checkboxes are numerically sequential though so I am not sure if this  
helps. I also had only a couple hours to do this from start to finish  
so I am sure there is a better way, but maybe this helps.


 I wrote a function that generates the row of checkboxes, then a  
function that combines them all into one field and so the status of  
every checkbox is in one field.



Function generates the checkboxes and checks in the array if that  
checkbox is checked or not.


function row_generator($row,$number,$array)
{
echo \ntr;
echo \n\tth align=\center\ valign=\top\Row $row/th;

$i = 1;
while ($i = $number)
{

if ($i  10)
{   $row_number = {$row}-0{$i}; }
else
{   $row_number = {$row}-{$i};  }

echo \n\ttd align=\center\ valign=\top\;
		echo input type=\checkbox\ name=\$row_number\ id=\$row_number 
\;


if (strstr($array,$row_number) === FALSE)
{   echo ;  }
else
{   echo  CHECKED;  }

echo ;
echo br;
echo $i;
echo /td;
$i++;

}
echo \n/tr;
}

In use:

$seats = $row['seats'];
row_generator(A,23,$seats);

Collect the posted Data and then later this gets input into a database

$poster_A = ;
$i = 1;
while ($i = 30)
{
if ($i  10) 
{   $r = 0{$i}; }
else
{   $r = $i;}
if (isset($_POST[A-$r]))
{   $poster_A .= A-$r;  
$poster_A .= :; }
$i++;
}

$seats = ({$poster_A}{$poster_B} etc);
$query = UPDATE seating_chart SET
seats = '$seats'
WHERE season = '2006';


--
Kevin Murphy
Webmaster: Information and Marketing Services
Western Nevada Community College
www.wncc.edu
775-445-3326


On May 17, 2006, at 11:21 AM, Rahul S. Johari wrote:


Ave,

I’m a little confused as to what’s the best way to handle this.
I have a form which, apart from lots of other fields, has a set of  
25 – 30
Check Boxes, each of which asks the user for some kind of  
information which

the user can check or leave unchecked.
The information each Check Box collects will also appear in the  
“Listing”

for users to view once the user has completed  submitted the form.
Furthermore, there is an Advanced Search also available to users  
which will
also provide the same 25 - 30 check boxes which define the search  
criteria.

I’m not sure what’s the best, most efficient way to do this.

The tedious way to do this is to make 30 fields in the mySQL  
database, and
if the check box is checked, the data goes into the corresponding  
field...
And similarly listing the data from the field if field is non- 
empty And

similarly including each field in the Search options.

I want suggestions for a better/faster way to do this. I did think  
about
creating a single field and storing the data from each ‘checked’  
check box
as comma separated values in the single field. I’m not sure how to  
do that
and if that’s the best way But even if I can, I’m not sure how  
to get
the data to display separately out of that field in the Listings  
view and

more importantly how to include that data in the Search options.

Any help would be appreciated.

Thanks,

Rahul S. Johari
Coordinator, Internet  Administration
Informed Marketing Services Inc.
500 Federal Street, Suite 201
Troy NY 12180

Tel: (518) 687-6700 x154
Fax: (518) 687-6799
Email: [EMAIL PROTECTED]
http://www.informed-sources.com



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