Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 5 of 5
  1. #1
    Senior Member
    Join Date
    Oct 2007
    Posts
    241
    Member #
    15910
    Hi,

    I am trying to modify the values I entered before into a mysql table column where I had entered links only. They were links however they did not have http://www. in the beginning (I was taking care of the proper display in php display file).

    From now, I want to enter links properly, so I changed the php file, without automatically adding/writing http://www. in the beginning, but this time the old values links dont work.

    How can I add http://www. to the beginning of all the old values in this column?

    Thanks

  2.  

  3. #2
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    There probably is an easier way to do this, but I tried the following against a test table I created and I could not get it to work.

    Code:
    UPDATE testTable SET linkColumn = "http://www." + linkColumn WHERE testID = 2
    Probably due to linkColumn being updated before I get to the + linkColumn part.

    So, I would suggest you select all rows that you want to update and then loop through them and using the result/recordset for the old linkColumn value.

  4. #3
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    + is a math operator only in MySQL.

    For concatenation do this:

    Code:
    UPDATE testTable 
    SET linkColumn = CONCAT("http://www.", linkColumn) 
    WHERE testID = 2

  5. #4
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    I was close!

    I should have known that, I got the idea from when I wrote a hit/usage type script.

    Case closed.

  6. #5
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    PS - The operator for concatenation in MySQL is || but I never use it because there's a support issue with it. Some installations of MySQL will translate || into an OR operaotor and will return a boolean result (usually FALSE or 0).

    The safe way to go is to use the CONCAT() function, which is supported by all ANSI-92 databases in the same way.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 10:29 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com