I am having trouble holding the result of a query in a var then having it print out later, here is the 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))
?>
<!-- spacer -->
<tr>
<td colspan=2> </td>
</tr>
<tr>
<td colspan=2 valign="top" align="left">
<b><font color="#3098C3"> Task/Hours Summary:</font></b>
</td>
</tr>
<tr>
<td valign="top" align="left">
<!-- tasks/hours summary -->
<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
<?
// 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
if (!$sum1) { $sum1 = 0; }
?>
<!-- spacer -->
<tr>
<td colspan=2> </td>
</tr>
<tr>
<td colspan=2 valign="top" align="left">
<b><font color="#3098C3"> Task/Hours Summary:</font></b>
</td>
</tr>
<tr>
<td valign="top" align="left">
<!-- tasks/hours summary -->
<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 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
----------------------------------------------------------------------------------------------