tags:

views:

225

answers:

2

Is there a logical (and possible) way to do something like this?

UPDATE $table SET LIKE %_checkbox = '' WHERE id='$id'

I have fields like allowed_checkbox and types_checkbox and they are sent to the database script dynamically. Can you use a wildcard when referring to the column name?

+1  A: 

No. You would have to generate the SQL string and then execute it separately. If you're trying to do something like this then you've probably got a bad schema design.

Joe Philllips
Okay. It's a class I've built to handle my database functions. I can add any elements to a form and it will handle them with a simple function call on $_POST. I guess I'll have to re-think how I handle this part of it. Thanks for the thoughts.
jeerose
+2  A: 

You've got a bit of a Frankenstein syntax there. The server will need to know the table and column names before compiling the SQL - so you can't do what you're after directly.

Does your php code have no prior knowledge of the database schema?

The key word you used is dynamically - you could find matching column names using a query against the MySQL INFORMATION_SCHEMA.COLUMNS table. You could do this per-update, which would be expensive, or once at application start up extract the schema for all tables you need.

martin clayton
Thanks for the extra advice martin. I knew it wasn't right but was just fishing for ideas. My Franky syntax seemed to get the point across I guess! Thanks again.
jeerose