Could someone help me with this mysql query?

Discussion in 'PHP' started by x0x, May 7, 2010.

  1. #1
    I have fields with numbers. I want to update the field and add commas and a text behind the number.

    Example

    1000 would become 10,000 MyText
    10000 would become 10,000 MyText

    Would it be possible?
     
    x0x, May 7, 2010 IP
  2. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #2
    Is the text the same for all numbers ?

    If it was, you could do a database backup, then a simple find/replace

    find 000 replace with ,000 MyText

    Then restore your database
     
    MyVodaFone, May 7, 2010 IP
  3. amaroks

    amaroks Peon

    Messages:
    242
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    hmmm i Do Not think that the query add the ( ,) to the number but there must be a way to show it when making an output query.
     
    amaroks, May 7, 2010 IP
  4. webrickco

    webrickco Active Member

    Messages:
    268
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #4
    If the field is numeric, then you simply can't. If the database field content is alphanumeric then you can build your sql string within your PHP code which gives you more coding capability than just trying to query it directly with a single mysql update. In an other hand, you will need to query the database twice in order to perform the operation. One for reading, one for updating. Replacing in between the string read with another one can be done using several methods: using regular expression for instance (which I don't like), or simply completing the string with standard and more human readable code using something as simple as:
    $string = substr($string, 0, strlen($string) - 3) . ",000 MyText";
     
    webrickco, May 7, 2010 IP
  5. x0x

    x0x Well-Known Member

    Messages:
    510
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    110
    #5
    Thanks guys, got it done the way webricko showed!
     
    x0x, May 7, 2010 IP