View Single Post
  #1  
Old 22nd Jan 04, 02:56 PM
JacKDynne's Avatar
JacKDynne JacKDynne is offline
Administrator
 
Join Date: Oct 2001
Location: The Past Through Tomorrow
Posts: 1,591
JacKDynne will become famous soon enoughJacKDynne will become famous soon enough
Send a message via MSN to JacKDynne
I am having trouble holding the result of a query in a var then having it print out later, here is the code:

Code:
<? //Set variable for sum1 $sum1 = 0; ?> <? // get current user sum of straight time $query = "SELECT SUM(hours) from log WHERE tid = '1' AND date = '$sdate' AND date = '$edate' AND uid = '$_SESSION[SESSION_UID]'"; $result = mysql_db_query($database, $query, $connection) or die ("Error in query: $query . " . mysql_error()); // Fetch first sum and hold in a var while ($sum1 = mysql_fetch_array($result)) &nbsp; ?> <!-- spacer --> <tr> <td colspan=2>&nbsp;</td> </tr> <tr> <td colspan=2 valign="top" align="left"> <b><font color="#3098C3">&nbsp;&nbsp;Task/Hours Summary:</font></b> </td> </tr> <tr> <td valign="top" align="left"> <!-- tasks/hours summary &nbsp;--> <table border="0" cellspacing="2" cellpadding="5"> <tr> <td valign=top align=left><font color=#D03468>Task</font></td> <td valign=top align=center><font color=#D03468>Hours</td> </tr> <tr> <td valign=top align=left><font color=#000000>Regular Hours</font><td valign=top align=center><font color=#000000><b><? echo print($sum1); ?></b></td> </tr> </table>
It keeps returning the array value as the result of the query, not the actual sum. I have run the query directly against the db in phpmyadmin and it returns the right value. Any ideas?

btw - please ignore the sloppy code, I have been cutting this script up all over the place

Mucho TIA

/JD
---------------------------------------------------------------------------------------------
EDIT - Making some progress... added/changed some code - now it seems that my query is not running right or somehow not returning the same value as when I run it straight against the db
Code:
<? // get current user sum of straight time $query = "SELECT SUM(hours) from log WHERE tid = '1' AND date = '$sdate' AND date = '$edate' AND uid = '$_SESSION[SESSION_UID]'"; $result = mysql_db_query($database, $query, $connection) or die ("Error in query: $query . " . mysql_error()); // Fetch first sum and hold in a var while ($sum1 = mysql_fetch_row($result)); // correction if sum is zero - explicitly assign it 0, so that it gets printed in report &nbsp; &nbsp;if (!$sum1) { $sum1 = 0; } &nbsp; ?> <!-- spacer --> <tr> <td colspan=2>&nbsp;</td> </tr> <tr> <td colspan=2 valign="top" align="left"> <b><font color="#3098C3">&nbsp;&nbsp;Task/Hours Summary:</font></b> </td> </tr> <tr> <td valign="top" align="left"> <!-- tasks/hours summary &nbsp;--> <table border="0" cellspacing="2" cellpadding="5"> <tr> <td valign=top align=left><font color=#D03468>Task</font></td> <td valign=top align=center><font color=#D03468>Hours</td> </tr> <tr> <td valign=top align=left><font color=#000000>Regular Hours</font> &nbsp;<td valign=top align=center><font color=#000000><b><? echo sprintf("%1.01f", $sum1); ?></b></td> </tr> </table>
/me keeps trying
----------------------------------------------------------------------------------------------
Edit Again - Seems the result is where my fault is - not sure what I am doing wrong - will keep trying
----------------------------------------------------------------------------------------------
__________________


Reply With Quote