SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist
    Join Date
    Jun 2010
    Posts
    453
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    space between data using CONCAT

    I've successfully combined data from two columns using this script:
    PHP Code:
    mysql_query("UPDATE catkey SET category_subcategory = CONCAT(category,subcategory)") or die(mysql_error()); 
    I'd like to put 4 blank spaces between the data in category and the data from subcategory when CONCAT fills the category_subcategory column. I've tried several variations of the above script without success.

    How to I need to change my script to add 4 blank spaces between the data?

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,250
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    there are two ways to do it
    Code:
    UPDATE catkey 
       SET category_subcategory = 
              CONCAT_WS('    ',category,subcategory)
    Code:
    UPDATE catkey 
       SET category_subcategory = 
              CONCAT(category,'    ',subcategory)
    i prefer the former method

    if you'd like to know how they differ, the mysql manual has a pretty decent explanation

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Evangelist
    Join Date
    Jun 2010
    Posts
    453
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your help r937.


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
  •