Results 1 to 3 of 3

Thread: PHP MYSQL Erase all fields beginning with...

  1. #1
    Join Date
    Jun 2007
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default PHP MYSQL Erase all fields beginning with...

    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

  2. #2
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    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)

  3. #3
    Join Date
    Jun 2007
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    all are varchar(9) if it helps. It is the status of many checkboxes I am trying to solve...

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •