Log in

View Full Version : PHP MYSQL Erase all fields beginning with...



lindm
06-10-2008, 06:13 PM
I have a couple of fields in a mysql database beginning with cx. I want to erase all these at the same time. Instead of the following:

mysql_query(
"UPDATE table SET

cx1 = '',
cx2 = '',
cx3 = '',
cx4 = '',
cx5 = '',
");

is there a short script solution that will do this for me without having to name all the fields? Perhaps a script that will search the table for all fields beginning with cx and create the query above?

Thanks

boogyman
06-10-2008, 06:51 PM
those fields are not very helpful in Lehman's terms, because looking at that table, I cannot tell what type of data will be in cx2 or cx5 without knowing alot more about the database schema and structure as a whole.

If, for instance, cx2 was replaced with "member id" I could postulate that this field would be an integer and it would probably be auto incrementing... also if cx5 was replaced with "name", I could postulate that this field will most likely be a "varchar" type and probably have a limit around 64.

I do believe you need to perform that query such as you have it there, unless you wanted to just delete the record all together (which has its pros and cons of its own)

lindm
06-10-2008, 07:58 PM
all are varchar(9) if it helps. It is the status of many checkboxes I am trying to solve...