[thelist] echoing col field names based on field values (php/mySQL)

Jeremy Weiss jweiss at cox-internet.com
Wed Jun 29 15:08:49 CDT 2005

I've got a database with a couple tables in it. One of the tables contains
basic info on condos. Another table is for all the 'features' the condo has.
The PK field is that of the condo table. The reason I stuck the features in
a separate table is b/c there's a good chance for more features to be added
on a continuing basis and it seemed like a good way to automate things so
that I'm not having to rewrite the queries later.  The fields are things
such as:
Cable TV

The possible values for these fields is '0' and '1'. What I want to happen
is when I pull a row from the database and display it, I only want to
display the features with a value of 1. This way I can just display a bullet
list of features that the condo has to offer.

I've got the code that will print out something along the lines of:

PK   Refrigerator   Range/oven   Microwave   Ceiling fan(s)   Cable TV
005  1                   1                  0                  0

What I'm wanting is something like:

* Refrigerator
* Range/oven
* Cable TV

Notice there's no mention of the PK field or of the fields with values of
'0'. So, I guess my first question should be, am I even going about this
right? Should I be redesigning the database or is there something simple in
the code that I'm over looking that would enable me to echo only the column
names whose value in the recordset are '1' ?


More information about the thelist mailing list