Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

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

  • 08-11-2008 08: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, Registered Users 2, Paid Member Posts: 3,519 ✭✭✭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, Registered Users 2 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, Registered Users 2 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, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    Good stuff :)


Advertisement