Jump to content


Photo

calculate each field records...need help!


  • Please log in to reply
3 replies to this topic

#1 bos

bos
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 07 October 2006 - 03:24 PM

------------------------------------
time              | id | cash
------------------------------------
2006-10-07  | 1  | 24000
2006-10-08  | 1  | 140000
------------------------------------

How him so that the calculation field 'cash' can be
380000,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;
480000160000
That I wanted results of the total number field record 'cash' to one,just like this
380000


#2 printf

printf
  • Staff Alumni
  • Advanced Member
  • 889 posts

Posted 07 October 2006 - 06:48 PM

You can do the math in your query!

$query = mysql_query ( "SELECT SUM(cash) AS total FROM saldo where id = 1" );

$result = mysql_fetch_assoc ( $query );

echo $result['total'];


me!


#3 bos

bos
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 07 October 2006 - 07:47 PM

$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 language

ownz by printf.....


thx 4 reply!!

#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 09 October 2006 - 05:46 AM

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?
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users