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
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.

 

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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!

 

:)

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.