bos Posted October 7, 2006 Share Posted October 7, 2006 ------------------------------------time | id | cash ------------------------------------2006-10-07 | 1 | 240002006-10-08 | 1 | 140000------------------------------------ How him so that the calculation field 'cash' can be380000,what the SQL or PHP order?..$df = mysql_query("SELECT * from saldo where id = '1'");if (!$df) {echo 'Could not run query1: ' . mysql_error();exit;} while ($sh = mysql_fetch_array($df)){$tk = $sh[1] + $sh[1];echo $tk;}But results above like;480000160000That I wanted results of the total number field record 'cash' to one,just like this380000 Quote Link to comment https://forums.phpfreaks.com/topic/23274-calculate-each-field-recordsneed-help/ Share on other sites More sharing options...
printf Posted October 7, 2006 Share Posted October 7, 2006 You can do the math in your query![code]$query = mysql_query ( "SELECT SUM(cash) AS total FROM saldo where id = 1" );$result = mysql_fetch_assoc ( $query );echo $result['total'];[/code]me! Quote Link to comment https://forums.phpfreaks.com/topic/23274-calculate-each-field-recordsneed-help/#findComment-105637 Share on other sites More sharing options...
bos Posted October 7, 2006 Author Share Posted October 7, 2006 $df = mysql_query("SELECT SUM(\x63\x61\x73\x68) AS total FROM vk_saldo where id = '1'");if (!$df) {echo 'Could not run query1: ' . mysql_error();exit;}greats !! its absolute worked...The order went correctly, you indeed the champion in the SQL languageownz by printf.....thx 4 reply!! Quote Link to comment https://forums.phpfreaks.com/topic/23274-calculate-each-field-recordsneed-help/#findComment-105647 Share on other sites More sharing options...
fenway Posted October 9, 2006 Share Posted October 9, 2006 Not that prinf's solution wasn't entirely correct, but I'm confused as to why PHP "guessed" the variable type wrong... aren't they weakly typed? Quote Link to comment https://forums.phpfreaks.com/topic/23274-calculate-each-field-recordsneed-help/#findComment-106092 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.