Moron Posted August 23, 2007 Share Posted August 23, 2007 My first query returns the following results: The query itself is: $RESULTDS=mssql_query("SELECT DV.[FY], DV.[EmpNo], DV.[NAME], DV.[EmpNo], M2.[NAMEL], M2.[NAMEF], M2.[NAMEMI], M2.[MSSNO], DV.[DATE OF SERVICE], DV.[^], DV.[sER(D-O-V-H)], DV.[CONSIDER], DV.[REIMBURSE] FROM DentalVisionHearing DV JOIN MASTERL2 M2 ON M2.[EMPNO]=DV.EmpNo WHERE M2.[MSSNO] = '".$_SESSION['password']."' and DV.[FY] = '$fiscal' ORDER BY DV.[FY] desc"); But when I try to sum the Amount Spent column (the "CONSIDER" field in the database), using this: $sql= "SELECT SUM(CONSIDER) FROM DentalVisionHearing DV JOIN MASTERL2 M2 ON M2.[EMPNO]=DV.EmpNo WHERE DV.[FY] = '$fiscal'" ; $result= mssql_query($sql); $row = mssql_fetch_array($result); echo $row['total '] ; ....it gives me nothing. No errors and the above results come right up, but why isn't this returning a SUM of the values in the "consider" field? Link to comment https://forums.phpfreaks.com/topic/66334-solved-why-does-sum-return-nothing/ Share on other sites More sharing options...
xyn Posted August 23, 2007 Share Posted August 23, 2007 try while($row = mssql_fetch_array($result)) { echo $row['total '] ; } Link to comment https://forums.phpfreaks.com/topic/66334-solved-why-does-sum-return-nothing/#findComment-331942 Share on other sites More sharing options...
Jessica Posted August 23, 2007 Share Posted August 23, 2007 Where is 'total' coming from? If you want SUM to be stored as 'total', you need to tell it so: $sql= "SELECT SUM(CONSIDER) AS total FROM DentalVisionHearing DV JOIN MASTERL2 M2 ON M2.[EMPNO]=DV.EmpNo WHERE DV.[FY] = '$fiscal'" ; $result= mssql_query($sql); $row = mssql_fetch_array($result); echo $row['total '] ; Link to comment https://forums.phpfreaks.com/topic/66334-solved-why-does-sum-return-nothing/#findComment-331949 Share on other sites More sharing options...
Moron Posted August 23, 2007 Author Share Posted August 23, 2007 Thanks, folks, but both of the above tactics echo nothing. Link to comment https://forums.phpfreaks.com/topic/66334-solved-why-does-sum-return-nothing/#findComment-332117 Share on other sites More sharing options...
akitchin Posted August 23, 2007 Share Posted August 23, 2007 i'm going to guess that it's one of two things: a syntax error, or the extra space in the key: $sql= "SELECT SUM(CONSIDER) AS total FROM DentalVisionHearing DV JOIN MASTERL2 M2 ON M2.[EMPNO]=DV.EmpNo WHERE DV.[FY] = '$fiscal'" ; $result= mssql_query($sql) or die(mssql_error()); $row = mssql_fetch_array($result); echo $row['total']; Link to comment https://forums.phpfreaks.com/topic/66334-solved-why-does-sum-return-nothing/#findComment-332124 Share on other sites More sharing options...
Moron Posted August 23, 2007 Author Share Posted August 23, 2007 i'm going to guess that it's one of two things: a syntax error, or the extra space in the key: $sql= "SELECT SUM(CONSIDER) AS total FROM DentalVisionHearing DV JOIN MASTERL2 M2 ON M2.[EMPNO]=DV.EmpNo WHERE DV.[FY] = '$fiscal'" ; $result= mssql_query($sql) or die(mssql_error()); $row = mssql_fetch_array($result); echo $row['total']; That works! THANK YOU!!! I added a piece into the "where" clause and that's perfect. Thanks! Link to comment https://forums.phpfreaks.com/topic/66334-solved-why-does-sum-return-nothing/#findComment-332132 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.