Moron Posted August 22, 2007 Share Posted August 22, 2007 My WHILE loop gives me the exact results I want: while ($RESULT = mssql_fetch_assoc($RESULTDS)) { echo "<tr>"; echo "<td align=center>"; echo "<font size=2 color=#000000 face=arial>"; echo $RESULT['DATE OF SERVICE']; echo "</font>"; echo "</td>"; echo "<td align=center>"; echo "<font size=2 color=#000000 face=arial>"; echo $RESULT['^']; echo "</font>"; echo "</td>"; echo "<td align=center>"; echo "<font size=2 color=#000000 face=arial>"; echo $RESULT['SER(D-O-V-H)']; echo "</font>"; echo "</td>"; echo "<td align=center>"; echo "<font size=2 color=#000000 face=arial>"; printf (" %01.2f", $RESULT['CONSIDER']); echo "</font>"; echo "</td>"; echo "<td align=center>"; echo "<font size=2 color=#000000 face=arial>"; printf (" %01.2f", $RESULT['REIMBURSE']); echo "</font>"; echo "</td>"; echo "</tr>"; $totalspent = $RESULT['CONSIDER']; } But how can I add the results fom the "consider" and the "reimburse" columns? Quote Link to comment https://forums.phpfreaks.com/topic/66211-how-can-i-add-these-results/ Share on other sites More sharing options...
piznac Posted August 22, 2007 Share Posted August 22, 2007 I have no idea what you are asking. Quote Link to comment https://forums.phpfreaks.com/topic/66211-how-can-i-add-these-results/#findComment-331188 Share on other sites More sharing options...
Moron Posted August 22, 2007 Author Share Posted August 22, 2007 I have no idea what you are asking. Within the WHILE loop, results are being returned as long as the criteria (employee number) matches. In the one I'm currently testing, the employee has four records appear. I want to add the results of the "consider" column. Quote Link to comment https://forums.phpfreaks.com/topic/66211-how-can-i-add-these-results/#findComment-331193 Share on other sites More sharing options...
piznac Posted August 22, 2007 Share Posted August 22, 2007 ohh,.. like add as in math? try sum($RESULT[CONSIDER]); Quote Link to comment https://forums.phpfreaks.com/topic/66211-how-can-i-add-these-results/#findComment-331197 Share on other sites More sharing options...
Moron Posted August 22, 2007 Author Share Posted August 22, 2007 ohh,.. like add as in math? Yes. Sorry for the confusion. In the example employee I'm using, the above code returns four records with varying amounts of money spent (the "consider" column). I want to add those results together. Quote Link to comment https://forums.phpfreaks.com/topic/66211-how-can-i-add-these-results/#findComment-331201 Share on other sites More sharing options...
piznac Posted August 22, 2007 Share Posted August 22, 2007 Ok yeah just do this: $total = sum($RESULT[CONSIDER]); echo $total; that should work. Quote Link to comment https://forums.phpfreaks.com/topic/66211-how-can-i-add-these-results/#findComment-331203 Share on other sites More sharing options...
Moron Posted August 22, 2007 Author Share Posted August 22, 2007 Ok yeah just do this: $total = sum($RESULT[CONSIDER]); echo $total; that should work. Hmm... this echoes nothing.... ??? Quote Link to comment https://forums.phpfreaks.com/topic/66211-how-can-i-add-these-results/#findComment-331211 Share on other sites More sharing options...
piznac Posted August 22, 2007 Share Posted August 22, 2007 hmm,.. well when you echo $RESULT[CONSIDER] in the while loop does it return the numbers? Quote Link to comment https://forums.phpfreaks.com/topic/66211-how-can-i-add-these-results/#findComment-331214 Share on other sites More sharing options...
Moron Posted August 22, 2007 Author Share Posted August 22, 2007 hmm,.. well when you echo $RESULT[CONSIDER] in the while loop does it return the numbers? It does. If I echo it after the WHILE loop, it echoes the value of the last record produced. Quote Link to comment https://forums.phpfreaks.com/topic/66211-how-can-i-add-these-results/#findComment-331218 Share on other sites More sharing options...
piznac Posted August 22, 2007 Share Posted August 22, 2007 Ohhhh Im sorry,. my bad,.. sum() is a sql function,. not a php one. So you would need to do it in your sql statement: Example: $query = "SELECT type, SUM(price) FROM products GROUP BY type"; echo $row['SUM(price)']; Does that make sense? Quote Link to comment https://forums.phpfreaks.com/topic/66211-how-can-i-add-these-results/#findComment-331226 Share on other sites More sharing options...
Moron Posted August 22, 2007 Author Share Posted August 22, 2007 Ohhhh Im sorry,. my bad,.. sum() is a sql function,. not a php one. So you would need to do it in your sql statement: Example: $query = "SELECT type, SUM(price) FROM products GROUP BY type"; echo $row['SUM(price)']; Does that make sense? It makes sense, but I'm having trouble getting it to work using my actual database parameters. Here's my first query which works fine: $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"); The adaptation I tried was: $RESULTDS=mssql_query("SELECT SUM(DV.[CONSIDER]) FROM DentalVisionHearing DV JOIN MASTERL2 M2 ON M2.[EMPNO]=DV.EmpNo WHERE M2.[MSSNO] = '".$_SESSION['password']."' and DV.[FY] = '$fiscal' "); $RESULT=mssql_fetch_assoc($RESULTDS) or die (mssql_get_last_message()); echo $RESULT['SUM(CONSIDER)']; It echoes nothing. Quote Link to comment https://forums.phpfreaks.com/topic/66211-how-can-i-add-these-results/#findComment-331242 Share on other sites More sharing options...
piznac Posted August 22, 2007 Share Posted August 22, 2007 Well this is a mysql function,.. hmmm you might want to look it up and see if there is something for mssql,.. not sure. Sorry I couldnt help. Quote Link to comment https://forums.phpfreaks.com/topic/66211-how-can-i-add-these-results/#findComment-331244 Share on other sites More sharing options...
Moron Posted August 22, 2007 Author Share Posted August 22, 2007 Well this is a mysql function,.. hmmm you might want to look it up and see if there is something for mssql,.. not sure. Sorry I couldnt help. From what I've seen, the functions are usually the same (except for using "mssql" instead of "mysql"). I probably still don't have the second query right. Thanks a ton for trying! Quote Link to comment https://forums.phpfreaks.com/topic/66211-how-can-i-add-these-results/#findComment-331254 Share on other sites More sharing options...
Moron Posted August 23, 2007 Author Share Posted August 23, 2007 Anyone else have input on this? Is there a way to do this math using PHP instead of the query -OR- is my query structured wrong? Quote Link to comment https://forums.phpfreaks.com/topic/66211-how-can-i-add-these-results/#findComment-331514 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.