SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Guru johnjohn2's Avatar
    Join Date
    Apr 2004
    Location
    here
    Posts
    746
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    best way to convert numbers to words in a table

    I'm using php and a postgresql 7.4 database. I have a table that has one field for storing numbers(such as 34.23) that represent dollar amounts. I then have another field field that I'd like to have the equivalent dollar amount but written out in words. For example:

    34.23 thirty-four dollars and twenty-three cents

    Does anyone know how I can do this with some sort of update query or something?

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,017
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    a quick google search turned up this thread --

    http://www.sitepoint.com/forums/showthread.php?t=226411
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Guru johnjohn2's Avatar
    Join Date
    Apr 2004
    Location
    here
    Posts
    746
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, I've been looking into that. I'm just not sure how to get the php code into the update query on multiple records.

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,017
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    you would simply do the translation prior to the INSERT for a new row

    as for catching your existing data up (a one-time update), this would have to be one of those rare cases where it's okay to do the database operation in a loop

    (most times, a database operation in a loop is much to be avoided)

    read in the table, store in an array (or whatever you php guys do), then loop over the array and update each row using the id and the translation

    you know, you really should be asking this in the php forum

    perhaps a kindly moderator will move this thread
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Guru johnjohn2's Avatar
    Join Date
    Apr 2004
    Location
    here
    Posts
    746
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok thanks i'll try your suggestion


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
  •