1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Batch Field Editing?

Discussion in 'PHP' started by nickharper, Oct 11, 2007.

  1. #1
    Hi,

    I have a database with 9000+ entries (recipes)

    Basically for the title they are for example:

    Cheese on Toast recipe
    Bacon Sandwich recipe

    Now, 9000 of those will take a very long time to edit so I just wondered if there was a command that would allow me to remove the " recipe" from the title on every post?

    Thanks
     
    nickharper, Oct 11, 2007 IP
  2. kreoton

    kreoton Peon

    Messages:
    229
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
  3. kreoton

    kreoton Peon

    Messages:
    229
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #3
    forgot to mention

    if you want to change value permanently use not SELECT but UPDATE statement
     
    kreoton, Oct 11, 2007 IP
    nickharper likes this.
  4. nickharper

    nickharper Active Member

    Messages:
    732
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    75
    #4
    Will this work with only half of a field though?
     
    nickharper, Oct 11, 2007 IP
  5. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #5
    EDIT: Beat me to it^^

    
    mysql_query("
        UPDATE table_name
        SET recipe_name = REPLACE(recipe_name, ' recipe', '')
    ") OR die(mysql_error());
    
    PHP:
    I could imagine this being good for search engines, but if you want to remove it, the above code should do what you want.

    You still should make a backup of the database though, before running queries that affect a high amount of rows.
     
    nico_swd, Oct 11, 2007 IP
    nickharper likes this.
  6. nickharper

    nickharper Active Member

    Messages:
    732
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    75
    #6
    Thankyou both for your help.

    This has worked.
     
    nickharper, Oct 11, 2007 IP