Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

[Solved] MySQL - how do I edit a field without replacing?

Options
  • 08-11-2008 8:53pm
    #1
    Closed Accounts Posts: 19,080 ✭✭✭✭


    Right now I have
    UPDATE forum_topics SET topic_title = '[Moved from the old forum] ' & topic_title WHERE forum_id=26 LIMIT 1
    
    UPDATE forum_topics SET topic_title = "[Moved from the old forum] " & topic_title WHERE forum_id=26 LIMIT 1
    
    UPDATE forum_topics SET topic_title = "[Moved from the old forum] " + topic_title WHERE forum_id=26 LIMIT 1
    

    So I have a forum with various topics in it. The forum is forum_id=26. The topic titles are topic_title. I'm going to move them all into another forum but first I want to edit the titles so that people will know where they've come from.

    I've like to prefix all the old topic titles with "[Moved from the old forum]".

    The methods I've tried above aren't working. Can anyone help?


Comments

  • Registered Users Posts: 3,568 ✭✭✭ethernet


    I don't see what the & is doing. Believe SQL uses the keyword AND instead of &. Does this work?
    UPDATE forum_topics SET title = '[Moved from the old forum]' WHERE forum_id = 26;
    


  • Closed Accounts Posts: 19,080 ✭✭✭✭Random


    If the value of title is currently "Cool new stuff" then I would like it to now be "[Moved from the old forum]Cool new stuff".

    I'm trying to basically make a = a+1 but with text .. if that makes sense ??


  • Registered Users Posts: 9,579 ✭✭✭Webmonkey


    Note sure but try this:
    UPDATE forum_topics SET topic_title = CONCAT('[Moved from the old forum] ', topic_title) WHERE forum_id=26 LIMIT 1
    


  • Closed Accounts Posts: 19,080 ✭✭✭✭Random


    That worked Webmonkey, thanks very much!


  • Registered Users Posts: 9,579 ✭✭✭Webmonkey


    You have no ; to seperate the two statements? - Amn't sure if you meant to put both in or not.


  • Advertisement
  • Closed Accounts Posts: 19,080 ✭✭✭✭Random


    You caught me before the edit ;)

    I did indeed forget to take the other statement out and only noticed this when pasting the error message here. :)

    Thanks for the help.


  • Registered Users Posts: 9,579 ✭✭✭Webmonkey


    Good stuff :)


Advertisement