Jump to content

[SOLVED] wrong sum?


techker

Recommended Posts

hey guys so i got this going but there sum is wrong??

 

$query2 = "SELECT COUNT( `to_t1` )-( `from_t1`)AS TotalNumber, SUM( `to_t1` )-( `from_t1`) AS Totalhours FROM `week1`; "; 
$result2 = mysql_query($query2) or die(mysql_error());

while($row = mysql_fetch_array($result2)) {

  echo $row['Totalhours'] ." H";
}

21H

 

to_t1 is 17:30 and from_t1 is 9:30

 

how does it get 21?i need 8h

 

Link to comment
Share on other sites

Retrieve the data, then use PHP to do it:

 

$color = ($Totalhours > 40) ? 'red' : 'blue';  // $Totalhours var is value retrieved from table result

 

echo 'Total hours: <font color="', $color, '">', $Totalhours, '</font>';  // Better to use CSS - this is just an example

 

 

 

 

 

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.