Jump to content

How can I add these results?


Moron

Recommended Posts

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?

 

Link to comment
https://forums.phpfreaks.com/topic/66211-how-can-i-add-these-results/
Share on other sites

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.

 

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.

 

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!

 

:)

 

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.