Page 1 of 3 123 LastLast
Results 1 to 10 of 23
  1. #1
    Join Date
    Jul 2008
    Location
    Hastings, UK.
    Posts
    2,050
    Tokens
    0

    Latest Awards:

    Default [PHP] Maths + MySQL?

    id amount time date miscdesc
    1 £7.64 20:32 05/10/2008 Initial start-off amount

    There will be more columns, but what code would I use to get the total of all the digits added together (I know I will remove the £)

  2. #2
    Join Date
    Jan 2006
    Location
    Kent
    Posts
    987
    Tokens
    0

    Default

    use mysql_fetch_array, add them using array_sum(). There might be an easier way, i'm not brilliant at php ;p
    This is our situation and we're happy to be here,
    I wouldn't change this place for anything.


  3. #3
    Join Date
    Sep 2006
    Location
    Evanston, Illinois.
    Posts
    2,361
    Tokens
    0

    Latest Awards:

    Default

    Your not making yourself clear, can you give an example?

    I presume you want 764203205102008 if your taking all the digits out.

    Use str_replace after concatenating each of the strings in a variable.

    @above:

    array_sum needs integers or floats (php.net).

    So. heres the code to do that.

    PHP Code:
    $str '';
    $row mysql_fetch_array($query);
    foreach(
    $row as $key => $val) {
        
    $str .= $val// TESTME
    }
    $unwantedSymbols = array('£'':''/'); // Change to unicode values
    foreach($unwantedSymbols as $unwantedSymbol) {
        
    $str str_replace($unwantedSymbol''$str);


    Test this.
    Last edited by Hypertext; 05-10-2008 at 08:27 PM.
    How could this hapen to meeeeeeeeeeeeeee?lol.

  4. #4
    Join Date
    Jan 2006
    Location
    Kent
    Posts
    987
    Tokens
    0

    Default

    Ah okay, thanks
    Maybe he could strip all the symbols out using some function? and then add them?
    This is our situation and we're happy to be here,
    I wouldn't change this place for anything.


  5. #5
    Join Date
    Sep 2006
    Location
    Evanston, Illinois.
    Posts
    2,361
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Joe! View Post
    Ah okay, thanks
    Maybe he could strip all the symbols out using some function? and then add them?
    My code above should work.
    How could this hapen to meeeeeeeeeeeeeee?lol.

  6. #6
    Join Date
    Jul 2008
    Location
    Hastings, UK.
    Posts
    2,050
    Tokens
    0

    Latest Awards:

    Default

    well say i have 8 rows which are different numbers, what code would I create/or functions to sum them all up (+)

  7. #7
    Join Date
    Sep 2006
    Location
    Evanston, Illinois.
    Posts
    2,361
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Calon View Post
    well say i have 8 rows which are different numbers, what code would I create/or functions to sum them all up (+)
    Your still not making yourself clear, could you give us an example table, and an example output of what you'd like?
    How could this hapen to meeeeeeeeeeeeeee?lol.

  8. #8
    Join Date
    Jul 2008
    Location
    Hastings, UK.
    Posts
    2,050
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Hypertext View Post
    Your still not making yourself clear, could you give us an example table, and an example output of what you'd like?
    Table: money
    Columns: amount, id, miscdesc

    1: 7.50
    2: 7.50
    3: 7.50

    Well, how ever many columns I end up with..

    Something to add the columns together giving me a total number of the amount field.

  9. #9
    Join Date
    Sep 2006
    Location
    Evanston, Illinois.
    Posts
    2,361
    Tokens
    0

    Latest Awards:

    Default

    :rolleyes:

    I'll say it the third time. Example output?
    How could this hapen to meeeeeeeeeeeeeee?lol.

  10. #10
    Join Date
    Jul 2008
    Location
    Hastings, UK.
    Posts
    2,050
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Hypertext View Post
    :rolleyes:

    I'll say it the third time. Example output?
    :S I don't understand what you want.

    Output: 22.50 i think

Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •