Re: [PHP] Math problems (No not high school math!)

2008-09-25 Thread Stephen

Jason Pruim wrote:
So I'm trying to figure out how to do a little math in php to add up 
the number of hours that people have worked (Still on the timecard for 
anyone following along at home)


I have it inserting time in and timeout as timestamps into a MySQL 
database, from there, I use a while loop to display the total hours 
for the day which works perfectly, now though, they want it to total 
for the week...


Consider adding a column for the total hours and calculate it when 
saving the record.


It should make everything that follows easier.

Stephen

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Math problems (No not high school math!)

2008-09-25 Thread Jim Lucas
Jason Pruim wrote:
 So I'm trying to figure out how to do a little math in php to add up the
 number of hours that people have worked (Still on the timecard for
 anyone following along at home)
 
 I have it inserting time in and timeout as timestamps into a MySQL
 database, from there, I use a while loop to display the total hours for
 the day which works perfectly, now though, they want it to total for the
 week...
 
 I think what I need to do is create an array of my total time for the
 day then add that up in another loop to display the total... That seems
 like overkill to me though... is there a better way to do it?
 
 Here is the relevant part of the code:
 
 while ($row = mysql_fetch_assoc($result)){
 $timein = date(m/d/y h:i:s, $row['timein']);
 $timeout = date(m/d/y h:i:s, $row['timeout']);
 $totalday = ($row['timeout'] - $row['timein']);
 $totalday = $totalday/60/60;
 $totalday = round($totalday, 2);
 $totalweek = [EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL 
 PROTECTED]@#?#$*^

 echo ADMIN


 tr
 td{$row['Name']}/td
 td{$timein}/td
 td{$timeout}/td
 td{$totalday}/td

 /tr

 ADMIN;
 }   
 echo /table
 /div
 /body;
 
 -- 
 
 Jason Pruim
 Raoset Inc.
 Technology Manager
 MQC Specialist
 11287 James St
 Holland, MI 49424
 www.raoset.com
 [EMAIL PROTECTED]
 
 
 
 
 

Doesn't seem logical to have the weekly total displayed at the end of each
day.  Are you wanting a subtotal of each day being added to the weekly total
to be displayed next to each day?  If that is the case, the just have one
variable that you add each days total to that doesn't get reset when the new
DAY is started.

-- 
Jim Lucas

   Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them.

Twelfth Night, Act II, Scene V
by William Shakespeare


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Math problems (No not high school math!)

2008-09-25 Thread Jason Pruim


On Sep 25, 2008, at 11:28 AM, Jim Lucas wrote:


Jason Pruim wrote:
So I'm trying to figure out how to do a little math in php to add  
up the

number of hours that people have worked (Still on the timecard for
anyone following along at home)

I have it inserting time in and timeout as timestamps into a MySQL
database, from there, I use a while loop to display the total hours  
for
the day which works perfectly, now though, they want it to total  
for the

week...

I think what I need to do is create an array of my total time for the
day then add that up in another loop to display the total... That  
seems

like overkill to me though... is there a better way to do it?

Here is the relevant part of the code:

while ($row = mysql_fetch_assoc($result)){
   $timein = date(m/d/y h:i:s, $row['timein']);
   $timeout = date(m/d/y h:i:s, $row['timeout']);
   $totalday = ($row['timeout'] - $row['timein']);
   $totalday = $totalday/60/60;
   $totalday = round($totalday, 2);
   $totalweek = [EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL 
PROTECTED]@#?#$*^

   echo ADMIN


   tr
   td{$row['Name']}/td
   td{$timein}/td
   td{$timeout}/td
   td{$totalday}/td

   /tr

ADMIN;
   }
   echo /table
   /div
   /body;

--

Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
11287 James St
Holland, MI 49424
www.raoset.com
[EMAIL PROTECTED]







Doesn't seem logical to have the weekly total displayed at the end  
of each
day.  Are you wanting a subtotal of each day being added to the  
weekly total
to be displayed next to each day?  If that is the case, the just  
have one
variable that you add each days total to that doesn't get reset when  
the new

DAY is started.



Hi Jim,

You are correct, I want it to look something like this:
Name | time in | timeout | total for day
Name | time in | timeout | total for day
Name | time in | timeout | total for day
Name | time in | timeout | total for day
Name | time in | timeout | total for day
Name | time in | timeout | total for day
Name | time in | timeout | total for day
TOTAL FOR WEEK: X





--
Jim Lucas

  Some men are born to greatness, some achieve greatness,
  and some have greatness thrust upon them.

Twelfth Night, Act II, Scene V
   by William Shakespeare




--

Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
11287 James St
Holland, MI 49424
www.raoset.com
[EMAIL PROTECTED]





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Math problems (No not high school math!)

2008-09-25 Thread Jim Lucas
Jason Pruim wrote:
 
 On Sep 25, 2008, at 11:28 AM, Jim Lucas wrote:
 
 Jason Pruim wrote:
 So I'm trying to figure out how to do a little math in php to add up the
 number of hours that people have worked (Still on the timecard for
 anyone following along at home)

 I have it inserting time in and timeout as timestamps into a MySQL
 database, from there, I use a while loop to display the total hours for
 the day which works perfectly, now though, they want it to total for the
 week...

 I think what I need to do is create an array of my total time for the
 day then add that up in another loop to display the total... That seems
 like overkill to me though... is there a better way to do it?

 Here is the relevant part of the code:

 while ($row = mysql_fetch_assoc($result)){
$timein = date(m/d/y h:i:s, $row['timein']);
$timeout = date(m/d/y h:i:s, $row['timeout']);
$totalday = ($row['timeout'] - $row['timein']);
$totalday = $totalday/60/60;
$totalday = round($totalday, 2);
$totalweek = [EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL 
 PROTECTED]@#?#$*^

echo ADMIN


tr
td{$row['Name']}/td
td{$timein}/td
td{$timeout}/td
td{$totalday}/td

/tr

 ADMIN;
}
echo /table
/div
/body;

 -- 

 Jason Pruim
 Raoset Inc.
 Technology Manager
 MQC Specialist
 11287 James St
 Holland, MI 49424
 www.raoset.com
 [EMAIL PROTECTED]






 Doesn't seem logical to have the weekly total displayed at the end of
 each
 day.  Are you wanting a subtotal of each day being added to the weekly
 total
 to be displayed next to each day?  If that is the case, the just have one
 variable that you add each days total to that doesn't get reset when
 the new
 DAY is started.
 
 
 Hi Jim,
 
 You are correct, I want it to look something like this:
 Name | time in | timeout | total for day
 Name | time in | timeout | total for day
 Name | time in | timeout | total for day
 Name | time in | timeout | total for day
 Name | time in | timeout | total for day
 Name | time in | timeout | total for day
 Name | time in | timeout | total for day
 TOTAL FOR WEEK: X
 
 


 -- 
 Jim Lucas

   Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them.

 Twelfth Night, Act II, Scene V
by William Shakespeare


 
 -- 
 
 Jason Pruim
 Raoset Inc.
 Technology Manager
 MQC Specialist
 11287 James St
 Holland, MI 49424
 www.raoset.com
 [EMAIL PROTECTED]
 
 
 
 
 

This should work for you.

$totalWeek = 0;  // Initialize total holder

while ($row = mysql_fetch_assoc($result)){
$timein = date(m/d/y h:i:s, $row['timein']);
$timeout = date(m/d/y h:i:s, $row['timeout']);
$totalday = ($row['timeout'] - $row['timein']);
$totalday = $totalday/60/60;
$totalday = round($totalday, 2);

$totalWeek += totalday;  // Builds the total from the daily total

echo ADMIN


tr
td{$row['Name']}/td
td{$timein}/td
td{$timeout}/td
td{$totalday}/td

/tr

ADMIN;
}

# Display Weekly total
echo WEEKTOTAL

tr
td colspan='4' align='right'TOTAL FOR WEEK: {$totalWeek}/td
/tr

WEEKTOTAL;

echo /table
/div
/body;

-- 
Jim Lucas

   Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them.

Twelfth Night, Act II, Scene V
by William Shakespeare


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Math problems (No not high school math!)

2008-09-25 Thread Simcha


 -Original Message-
 From: Jason Pruim [mailto:[EMAIL PROTECTED]
 Subject: [PHP] Math problems (No not high school math!)
 
 So I'm trying to figure out how to do a little math in php to add up
 the number of hours that people have worked (Still on the timecard for
 anyone following along at home)

Something like this should work:
Select SUM(timediff(`timeout`, `timein`)) where date = X;
And for a week:
Select SUM(timediff(`timeout`, `timein`)) where week(date) = week_of_year ;

(Not tested)


Simcha Younger




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Math problems (No not high school math!)

2008-09-25 Thread Jason Pruim


On Sep 25, 2008, at 11:44 AM, Jim Lucas wrote:


Jason Pruim wrote:


On Sep 25, 2008, at 11:28 AM, Jim Lucas wrote:


Jason Pruim wrote:
So I'm trying to figure out how to do a little math in php to add  
up the

number of hours that people have worked (Still on the timecard for
anyone following along at home)

I have it inserting time in and timeout as timestamps into a MySQL
database, from there, I use a while loop to display the total  
hours for
the day which works perfectly, now though, they want it to total  
for the

week...

I think what I need to do is create an array of my total time for  
the
day then add that up in another loop to display the total... That  
seems

like overkill to me though... is there a better way to do it?

Here is the relevant part of the code:

while ($row = mysql_fetch_assoc($result)){
  $timein = date(m/d/y h:i:s, $row['timein']);
  $timeout = date(m/d/y h:i:s, $row['timeout']);
  $totalday = ($row['timeout'] - $row['timein']);
  $totalday = $totalday/60/60;
  $totalday = round($totalday, 2);
  $totalweek = [EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL 
PROTECTED]@#?#$*^

  echo ADMIN


  tr
  td{$row['Name']}/td
  td{$timein}/td
  td{$timeout}/td
  td{$totalday}/td

  /tr

ADMIN;
  }
  echo /table
  /div
  /body;

--

Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
11287 James St
Holland, MI 49424
www.raoset.com
[EMAIL PROTECTED]







Doesn't seem logical to have the weekly total displayed at the end  
of

each
day.  Are you wanting a subtotal of each day being added to the  
weekly

total
to be displayed next to each day?  If that is the case, the just  
have one

variable that you add each days total to that doesn't get reset when
the new
DAY is started.



Hi Jim,

You are correct, I want it to look something like this:
Name | time in | timeout | total for day
Name | time in | timeout | total for day
Name | time in | timeout | total for day
Name | time in | timeout | total for day
Name | time in | timeout | total for day
Name | time in | timeout | total for day
Name | time in | timeout | total for day
   TOTAL FOR WEEK: X





--
Jim Lucas

 Some men are born to greatness, some achieve greatness,
 and some have greatness thrust upon them.

Twelfth Night, Act II, Scene V
  by William Shakespeare




--

Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
11287 James St
Holland, MI 49424
www.raoset.com
[EMAIL PROTECTED]







This should work for you.

$totalWeek = 0;  // Initialize total holder

while ($row = mysql_fetch_assoc($result)){
   $timein = date(m/d/y h:i:s, $row['timein']);
   $timeout = date(m/d/y h:i:s, $row['timeout']);
   $totalday = ($row['timeout'] - $row['timein']);
   $totalday = $totalday/60/60;
   $totalday = round($totalday, 2);

   $totalWeek += totalday;  // Builds the total from the  
daily total


   echo ADMIN


   tr
   td{$row['Name']}/td
   td{$timein}/td
   td{$timeout}/td
   td{$totalday}/td

   /tr

ADMIN;
   }

# Display Weekly total
echo WEEKTOTAL

   tr
   td colspan='4' align='right'TOTAL FOR WEEK:  
{$totalWeek}/td

   /tr

WEEKTOTAL;

   echo /table
   /div
   /body;

Hi Everyone,

Just letting you all know (And for the archives) that I decided to use  
Jim's solution provided above. It works perfectly for what I am  
attempting to do.


Thanks to everyone for their help!


--

Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
11287 James St
Holland, MI 49424
www.raoset.com
[EMAIL PROTECTED]





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Math problems (No not high school math!)

2008-09-25 Thread Richard Lynch
Run another query and let MySQL add it up.

 -Original Message-
 From: Jason Pruim [mailto:[EMAIL PROTECTED]
 Sent: Thursday, September 25, 2008 10:05 AM
 To: PHP General List
 Subject: [PHP] Math problems (No not high school math!)

 So I'm trying to figure out how to do a little math in php to add up
 the number of hours that people have worked (Still on the timecard for
 anyone following along at home)

 I have it inserting time in and timeout as timestamps into a MySQL
 database, from there, I use a while loop to display the total hours
 for the day which works perfectly, now though, they want it to total
 for the week...

 I think what I need to do is create an array of my total time for the
 day then add that up in another loop to display the total... That
 seems like overkill to me though... is there a better way to do it?

 Here is the relevant part of the code:

 while ($row = mysql_fetch_assoc($result)){
 $timein = date(m/d/y h:i:s, $row['timein']);
 $timeout = date(m/d/y h:i:s,
 $row['timeout']);
 $totalday = ($row['timeout'] - $row['timein']);
 $totalday = $totalday/60/60;
 $totalday = round($totalday, 2);
 $totalweek =
 [EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@#?#$*^

 echo ADMIN


 tr
 td{$row['Name']}/td
 td{$timein}/td
 td{$timeout}/td
 td{$totalday}/td

 /tr

 ADMIN;
 }
 echo /table
 /div
 /body;

 --

 Jason Pruim
 Raoset Inc.
 Technology Manager
 MQC Specialist
 11287 James St
 Holland, MI 49424
 www.raoset.com
 [EMAIL PROTECTED]





___

The  information in this email or in any file attached
hereto is intended only for the personal and confiden-
tial  use  of  the individual or entity to which it is
addressed and may contain information that is  propri-
etary  and  confidential.  If you are not the intended
recipient of this message you are hereby notified that
any  review, dissemination, distribution or copying of
this message is strictly prohibited.  This  communica-
tion  is  for information purposes only and should not
be regarded as an offer to sell or as  a  solicitation
of an offer to buy any financial product. Email trans-
mission cannot be guaranteed to be  secure  or  error-
free. P6070214

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php