Jump to content

MYSQL SUM PROBLEM


gevensen

Recommended Posts

I have a query that works fine on myphpadmin but does not return a value using mysql_query in php

 

its is a SUM function

 

the field is a decimal 10,2

 

index is set

 

is there something in the mysql setup i could be doing wrong it should be working

mysql_connect($servername, $dbusername, $dbpassword) or die(mysql_error());
$dbname=$_SESSION['db'];
mysql_select_db($dbname) or die("CANNOT SELECT DATABASE - ". mysql_error());
$year='2009'; //$_SESSION['ytd_year'];
$query="SELECT * FROM sc_business_report ";
$result=mysql_query($query) or die(mysql_error());
if($result){
while($row=mysql_fetch_array($result)){
$fund=$row['fund'];
$account=$row['account'];
$query2="SELECT SUM( `split_amount` )AS `total` 
FROM `sc_expenses_transactions` 
WHERE  `fund` = '$fund' 
AND `account` = '$account'  
AND YEAR ( `date_of_split` ) = '$year'  ";



$result2=mysql_query($query2) or die(mysql_error());
if($result2){
	$row2=mysql_fetch_assoc($result2);
	echo $query2."<br />";
	echo "<br />VAR DUMP<br />";
	var_dump($row2);
	echo "<br />VAR DUMP<br />";
	echo $row2['total']."<br />";
} // eof result2
mysql_free_result($result2);	
}// eof while

} //eof result

 

 

Link to comment
https://forums.phpfreaks.com/topic/184156-mysql-sum-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.