Mysql Math Problem
Posted: Sun Jul 18, 2004 10:45 am
Ok here is what I have
A 2 mysql columns with money values with quantities:
atest / btest
5.00 / 2
5.50 /5
I want to be able to
times atest row 1 with btest row 1
times atest row 2 with btest row 2
and so on then add a total
So what I have been trying is taking the data from the db into two arrays times them and then adding the sum but after the data is retrieved it chages it into a string so I changed it back into a array but it still isn't working right.
A 2 mysql columns with money values with quantities:
atest / btest
5.00 / 2
5.50 /5
I want to be able to
times atest row 1 with btest row 1
times atest row 2 with btest row 2
and so on then add a total
Code: Select all
$query = "SELECT * FROM test";
$countRows = $db_mysql->query($query);
while ($countRow = mysql_fetch_array($countRows, MYSQL_ASSOC)) {
$total = $countRowї'atest'] * $countRowї'btest'] . " ";
$total2 = explode(" ", $total);
}
echo array_sum($total2);