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 £)

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 £)
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.
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.
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.
well say i have 8 rows which are different numbers, what code would I create/or functions to sum them all up (+)
How could this hapen to meeeeeeeeeeeeeee?lol.
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.
:rolleyes:
I'll say it the third time. Example output?
How could this hapen to meeeeeeeeeeeeeee?lol.
Want to hide these adverts? Register an account for free!