BetaONE will rise again!


Reply
  #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
  #2  
Old 27th Jan 04, 08:11 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
Resolved

This is how:

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()); $reghrs = mysql_result($result, 0); // correction if sum is zero - explicitly assign it 0, so that it gets printed in report if (!$reghrs) { $reghrs = 0; } ?>
and this to print it:

Code:
<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", $reghrs); ?></b></td> </tr>
Props out to Sephiroth

/JD
__________________


Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 06:13 AM.


Design by Vjacheslav Trushkin for phpBBStyles.com.
Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.