gevensen Posted December 6, 2009 Share Posted December 6, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/184156-mysql-sum-problem/ Share on other sites More sharing options...
gevensen Posted December 6, 2009 Author Share Posted December 6, 2009 i added trim to $account=trim($row['account']); Quote Link to comment https://forums.phpfreaks.com/topic/184156-mysql-sum-problem/#findComment-972282 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.