Re: Looking for specific data

From: Date: Thu, 22 Nov 2007 02:42:59 +0000
Subject: Re: Looking for specific data
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-44354@lists.php.net to get a copy of this message
DeadTOm wrote:
There has to be an easier way to do this. I have a page with a list of 29 options utilizing checkboxes. The options that are checked get put into a mysql table as a 1 and the options not checked get entered as a 0. So the table looks like this
id    cs01     cs02     cs03     cs04
1        0         0             1         0
2         1        0             0         0
3         0        0             0         1
The problem I'm running into is getting these things back out of the table. I only want the columns where the answer is a 1.
Try this? [ requires mysql 4.0+ ] select id, 'cs01' as column_name from table where cs01='1' union all select id, 'cs02' as column_name from table where cs02='1' union all select id, 'cs03' as column_name from table where cs03='1' union all select id, 'cs04' as column_name from table where cs04='1'; -- Postgresql & php tutorials http://www.designmagick.com/

« previous php.db (#44354) next »