php-general Digest 26 Sep 2008 00:27:44 -0000 Issue 5702
Topics (messages 280915 through 280943):
Re: calling functions from one or multiple files
280915 by: tedd
280940 by: Jochem Maas
280941 by: Ashley Sheridan
280942 by: Jochem Maas
Re: Questions regarding limits of processes launched by system, exec,
passthru ...
280916 by: Richard Lynch
280917 by: Daniel Brown
Re: Pass parameters via url inside a php cron job
280918 by: Daniel Brown
Math problems (No not high school math!)
280919 by: Jason Pruim
280920 by: Stephen
280921 by: Nathan Rixham
280922 by: Jason Pruim
280923 by: Jim Lucas
280924 by: Jason Pruim
280925 by: Jason Pruim
280926 by: Jim Lucas
280927 by: Maciek Sokolewicz
280928 by: Simcha
280930 by: Jason Pruim
280931 by: Lupus Michaelis
280934 by: Richard Lynch
Re: Wierd Variable Initialization
280929 by: VamVan
Filters and sanitizing a regexp
280932 by: Frank Stanovcak
280933 by: Frank Stanovcak
280935 by: Boyd, Todd M.
280936 by: Richard Heyes
280937 by: Boyd, Todd M.
280943 by: Bastien Koert
Re: Don't understand what is this $arr['N']['#']
280938 by: ANR Daemon
Re: The Data Literacy Test
280939 by: Jochem Maas
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[EMAIL PROTECTED]
----------------------------------------------------------------------
--- Begin Message ---
At 3:44 PM -0400 9/24/08, Robert Cummings wrote:
Seems kind of silly to have every function in it's own file. Also seems
kind of cluttered ot have every function in one file.
Now grouping related functions into a single file... that's sounds like
a good middle ground.
Cheers,
Rob.
The Goldie Locks solution.
Cheers,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
--- End Message ---
--- Begin Message ---
tedd schreef:
> At 3:44 PM -0400 9/24/08, Robert Cummings wrote:
>> Seems kind of silly to have every function in it's own file. Also seems
>> kind of cluttered ot have every function in one file.
>>
>> Now grouping related functions into a single file... that's sounds like
>> a good middle ground.
>>
>> Cheers,
>> Rob.
>
> The Goldie Locks solution.
otherwise known as mediorce ... rather like his blowup doll :-P
>
> Cheers,
>
> tedd
--- End Message ---
--- Begin Message ---
On Fri, 2008-09-26 at 01:05 +0200, Jochem Maas wrote:
> tedd schreef:
> > At 3:44 PM -0400 9/24/08, Robert Cummings wrote:
> >> Seems kind of silly to have every function in it's own file. Also seems
> >> kind of cluttered ot have every function in one file.
> >>
> >> Now grouping related functions into a single file... that's sounds like
> >> a good middle ground.
> >>
> >> Cheers,
> >> Rob.
> >
> > The Goldie Locks solution.
>
> otherwise known as mediorce ... rather like his blowup doll :-P
>
> >
> > Cheers,
> >
> > tedd
>
>
Why does it always come back to that poor doll?!
Ash
www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
Ashley Sheridan schreef:
> On Fri, 2008-09-26 at 01:05 +0200, Jochem Maas wrote:
>> tedd schreef:
>>> At 3:44 PM -0400 9/24/08, Robert Cummings wrote:
>>>> Seems kind of silly to have every function in it's own file. Also seems
>>>> kind of cluttered ot have every function in one file.
>>>>
>>>> Now grouping related functions into a single file... that's sounds like
>>>> a good middle ground.
>>>>
>>>> Cheers,
>>>> Rob.
>>> The Goldie Locks solution.
>> otherwise known as mediorce ... rather like his blowup doll :-P
>>
>>> Cheers,
>>>
>>> tedd
>>
> Why does it always come back to that poor doll?!
dunno, but it's rather apt to say 'screw the doll' :-P
>
>
> Ash
> www.ashleysheridan.co.uk
>
>
--- End Message ---
--- Begin Message ---
> -----Original Message-----
> Is there a way to limit the memory consumption and / or the CPU
> consumption of processes launched by the php functions system,
> exec, passthru, proc_open and shell_exec?
I suspect...
PHP pretty much releases control to the shell or whatever, and just waits
around for it to finish.
You'll have to put limits into the called processes, I think....
I could be wrong.
_______________________________________________________
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
--- End Message ---
--- Begin Message ---
On Thu, Sep 25, 2008 at 4:28 AM, Valentin Schmid - ICSurselva AG
<[EMAIL PROTECTED]> wrote:
> Hello all,
>
> Is there a way to limit the memory consumption and / or the CPU
> consumption of processes launched by the php functions system,
> exec, passthru, proc_open and shell_exec?
Since you're working on a *NIX system, check out PHP's pcntl_*
functions[1] and the *NIX `nice` function[2].
1: http://www.php.net/manual/en/ref.pcntl.php
2: http://www.manpagez.com/man/1/nice/
--
</Daniel P. Brown>
More full-root dedicated server packages:
Intel 2.4GHz/60GB/512MB/2TB $49.99/mo.
Intel 3.06GHz/80GB/1GB/2TB $59.99/mo.
Intel 2.4GHz/320/GB/1GB/3TB $74.99/mo.
Dedicated servers, VPS, and hosting from $2.50/mo.
--- End Message ---
--- Begin Message ---
On Thu, Sep 25, 2008 at 6:34 AM, Merlin Morgenstern
<[EMAIL PROTECTED]> wrote:
> Hello Jochem,
>
> thank you this has solved my problem:
> bla.php 2
> $tf = $argv[1];
Conversely, on a *NIX system, if you want to grab it via the web -
locally or from a remote server - you can do this:
* * * * * /bin/env GET
"http://www.example.com/index.html?example=given" >> /dev/null 2>&1
(^--- cron schedule) (^--- your URL)
--
</Daniel P. Brown>
More full-root dedicated server packages:
Intel 2.4GHz/60GB/512MB/2TB $49.99/mo.
Intel 3.06GHz/80GB/1GB/2TB $59.99/mo.
Intel 2.4GHz/320/GB/1GB/3TB $74.99/mo.
Dedicated servers, VPS, and hosting from $2.50/mo.
--- End Message ---
--- Begin Message ---
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]
--- End Message ---
--- Begin Message ---
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
--- End Message ---
--- Begin Message ---
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]
sounds like a mysql job.. whats the SQL?
--- End Message ---
--- Begin Message ---
On Sep 25, 2008, at 11:19 AM, Nathan Rixham 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]
sounds like a mysql job.. whats the SQL?
Actually where this is displayed, it is just a display portion, but
when I do the insert here is my SQL:
switch ($_GET['opt']){
case "signin";
//$sqlopt = "INSERT INTO `timeStore` ('timein', 'timeout',
'empID') VALUES('{$timenow}', 'NULL', '{$auth['empID']}')";
$sqlopt = "INSERT INTO `timeStore` VALUES(\"{$timenow}\", \"NULL
\", \"{$_SESSION['userInfo']['empID']}\", \"\",
\"{$_SESSION['userInfo']['fullname']}\")";
break;
case "signout";
$sqlopt = "UPDATE `timeStore` SET `timeout`=\"{$timenow}\" WHERE
`empID`=\"{$_SESSION['userInfo']['empID']}\" AND `timeout`=\"NULL\"";
break;
}
if(isset($_GET['opt'])){
mysql_query($sqlopt) or die("sqlopt failed: "
.mysql_error());
echo "<BR>SQL OPT: ".$sqlopt."<BR>";
header("Location: timecard.php");
echo "BReaking at opt get";
}
Yes I know it's ugly with all the escaping but I'm working my way
through that :P
--
Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
11287 James St
Holland, MI 49424
www.raoset.com
[EMAIL PROTECTED]
--- End Message ---
--- Begin Message ---
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
--- End Message ---
--- Begin Message ---
On Sep 25, 2008, at 11:24 AM, Jason Pruim wrote:
On Sep 25, 2008, at 11:19 AM, Nathan Rixham 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]
sounds like a mysql job.. whats the SQL?
Actually where this is displayed, it is just a display portion, but
when I do the insert here is my SQL:
switch ($_GET['opt']){
case "signin";
//$sqlopt = "INSERT INTO `timeStore` ('timein', 'timeout',
'empID') VALUES('{$timenow}', 'NULL', '{$auth['empID']}')";
$sqlopt = "INSERT INTO `timeStore` VALUES(\"{$timenow}\", \"NULL
\", \"{$_SESSION['userInfo']['empID']}\", \"\",
\"{$_SESSION['userInfo']['fullname']}\")";
break;
case "signout";
$sqlopt = "UPDATE `timeStore` SET `timeout`=\"{$timenow}\"
WHERE `empID`=\"{$_SESSION['userInfo']['empID']}\" AND `timeout`=
\"NULL\"";
break;
}
if(isset($_GET['opt'])){
mysql_query($sqlopt) or die("sqlopt failed: "
.mysql_error());
echo "<BR>SQL OPT: ".$sqlopt."<BR>";
header("Location: timecard.php");
echo "BReaking at opt get";
}
Yes I know it's ugly with all the escaping but I'm working my way
through that :P
Per an e-mail I just received suggesting that it may be wise to
include the select SQL here it is:
$sql = "SELECT * from `timestore` order by `empID`";
$row[]= mysql_query($sql) or die("Could not perform query: " .
mysql_error());
$result = $row[0];
--
Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
11287 James St
Holland, MI 49424
www.raoset.com
[EMAIL PROTECTED]
--- End Message ---
--- Begin Message ---
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]
--- End Message ---
--- Begin Message ---
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
--- End Message ---
--- Begin Message ---
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>";
--
How about having mysql do all the tedious stuff?
SELECT TIMESTAMPDIFF(HOUR, timein, timeout) FROM table WHERE
WEEK(timein) = $someWeek;
would give you the amount of hours between 2 time-values.
Then you could SUM it all up, group by user and return that.
SELECT SUM(timeout-timein) as secs, SUM(timeout-timein)/3600 as hours,
userid FROM table WHERE timein >= $START_OF_WEEK AND timeout <=
$END_OF_WEEK GROUP BY userid;
simple as that :)
--- End Message ---
--- Begin Message ---
> -----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
--- End Message ---
--- Begin Message ---
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]
--- End Message ---
--- Begin Message ---
Jason Pruim a écrit :
$totalday = $totalday/60/60;
If you're working with legal dates, this is wrong. A day can be 23 or
25 hours long. Thing about time changing (winter and summer time).
Use strtotime to avoid this kind of problems.
--
Mickaël Wolff aka Lupus Michaelis
http://lupusmic.org
--- End Message ---
--- Begin Message ---
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
--- End Message ---
--- Begin Message ---
Interesting. Thank you
On Thu, Sep 25, 2008 at 2:01 AM, Ford, Mike <[EMAIL PROTECTED]> wrote:
> On 25 September 2008 03:45, VamVan advised:
>
> > So guys,
> >
> > I found some thing strange that happened to me yesterday. Its small
> but
> > kinda freaked me out.
> >
> > So I have a tokenmap.php that I include include in different
> configuration
> > files. Some are classes and some are simple php files.
> >
> > So in my tokenmap.php I have declared an array as global.
> >
> > SO $GLOBAL['tokenmap'] = array()
> >
> > As a good programming practice what I did was:
> >
> > require_once('tokenmap.php');
> > $tokenmap = array();
> > $tokenmap = $GLOBAL['tokenmap'];
> > print_r($tokenmap);
> >
> > The above displays empty array
> >
> > But when I do this , it works
> >
> > require_once('tokenmap.php');
> > $tokenmap = $GLOBAL['tokenmap'];
> > print_r($tokenmap);
> >
> > Its kind of wierd for me. I am trying to understand. Can some one shed
> > some light on it for me.
>
> Well, $GLOBALS['tokenmap'] is *exactly* *the* *same* *thing* as
> $tokenmap when you're in the global scope (which I assume you are for
> what you describe here to make sense). So the assignment:
>
> $tokenmap = array();
>
> is the same as:
>
> $GLOBALS['tokenmap'] = array();
>
> And the assignment:
>
> $tokenmap = $GLOBALS['tokenmap'];
>
> is essentially useless as it's the same as:
>
> $tokenmap = $tokenmap;
>
> ... or:
>
> $GLOBALS['tokenmap'] = $tokenmap;
>
> ... or even:
>
> $GLOBALS['tokenmap'] = $GLOBALS['tokenmap'];
>
> Cheers!
>
> Mike
>
> --
> Mike Ford, Electronic Information Developer,
> C507, Leeds Metropolitan University, Civic Quarter Campus,
> Woodhouse Lane, LEEDS, LS1 3HE, United Kingdom
> Email: [EMAIL PROTECTED]
> Tel: +44 113 812 4730
>
>
>
>
> To view the terms under which this email is distributed, please go to
> http://disclaimer.leedsmet.ac.uk/email.htm
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
Is it possible to use the php filter function to sanitize a regular
expression such as to return just the date part of a string that may be
passed by an nonobservant user?
"#\d\d/\d\d/\d\d\d\d#"
input would be something like
as02/05/2008df
I want to use the filter to give me just the date should some oaf not leave
the date field as just digits.
--- End Message ---
--- Begin Message ---
by the by I'm using filter_var($string, FITER_VALIDATE_REGEXP, blah blah
blah)
""Frank Stanovcak"" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Is it possible to use the php filter function to sanitize a regular
> expression such as to return just the date part of a string that may be
> passed by an nonobservant user?
>
> "#\d\d/\d\d/\d\d\d\d#"
>
> input would be something like
> as02/05/2008df
>
> I want to use the filter to give me just the date should some oaf not
> leave the date field as just digits.
>
--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: Frank Stanovcak [mailto:[EMAIL PROTECTED]
> Sent: Thursday, September 25, 2008 12:41 PM
> To: [EMAIL PROTECTED]
> Subject: [PHP] Filters and sanitizing a regexp
>
> Is it possible to use the php filter function to sanitize a regular
> expression such as to return just the date part of a string that may
be
> passed by an nonobservant user?
>
> "#\d\d/\d\d/\d\d\d\d#"
>
> input would be something like
> as02/05/2008df
>
> I want to use the filter to give me just the date should some oaf not
> leave
> the date field as just digits.
Using preg_match and numbered groups, you could re-build the variable
like this:
<?php
$var = "as02/05/2008df";
$matches = array();
preg_match("#(\d{2})\D*(\d{2})\D*(\d{4})#", $var, $matches);
if(count($matches) != 4) {
echo "Invalid data<br />";
} else {
$filtered = $matches[1] . $matches[2] . $matches[3];
echo $filtered;
}
?>
HTH,
Todd Boyd
Web Programmer
--- End Message ---
--- Begin Message ---
> ...
Hi,
Had to have a play with this. Here's my (somewhat stricter) regex:
preg_match('/((?:[0-3]?[0-9])?\d)-([0-1]?\d)-20\d\d/', '31-12-2000', $matches);
if (!empty($matches[1]) AND $matches[1] > 31) $matches = array();
if (!empty($matches[2]) AND $matches[2] > 12) $matches = array();
You could probably do the checks for the day and month within the
regex, but it's late :-)
--
Richard Heyes
HTML5 Graphing for FF, Chrome, Opera and Safari:
http://www.phpguru.org/RGraph
--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
> Behalf Of Richard Heyes
> Sent: Thursday, September 25, 2008 2:28 PM
> To: Boyd, Todd M.
> Cc: Frank Stanovcak; [EMAIL PROTECTED]
> Subject: Re: [PHP] Filters and sanitizing a regexp
>
> > ...
>
> Hi,
>
> Had to have a play with this. Here's my (somewhat stricter) regex:
>
> preg_match('/((?:[0-3]?[0-9])?\d)-([0-1]?\d)-20\d\d/', '31-12-2000',
> $matches);
> if (!empty($matches[1]) AND $matches[1] > 31) $matches = array();
> if (!empty($matches[2]) AND $matches[2] > 12) $matches = array();
>
> You could probably do the checks for the day and month within the
> regex, but it's late :-)
I don't think that one is quite right... Your optionals (?) are
confusing. Why [0-3]?[0-9] AND the \d? Why [0-9] at all (since \d is
essentially [0-9])? Why use the discarded capture group (?:) since the
[0-3] is already optional?
It's on! :D
<?php
$var = "as12/32/2000df";
$matches = array();
preg_match('#(\d?[0-9])\D*([0-3]?\d)\D*(\d{4})#', $var, $matches);
if(count($matches) != 4 || $matches[1] > 12 || $matches[2] > 31)
$matches = NULL;
?>
MMDDYYYY 4 life, yo! Although, I would honestly prefer it if the world
went to YYYYMMDD as a standard. Just seems to sort itself out more
intuitively to the way I perceive time.
(FYI, I'm not sure about the if() statement working out or not... I'm
assuming PHP will drop through to the "then" part if there aren't 4
elements in the array instead of arbitrarily testing the
possibly-missing elements... but I didn't test that part.)
Also, I used \D* to save space (and confusion). You could just as easily
use (?:-|/) for hyphens or slashes.
Todd Boyd
Web Programmer
--- End Message ---
--- Begin Message ---
On Thu, Sep 25, 2008 at 3:57 PM, Boyd, Todd M. <[EMAIL PROTECTED]> wrote:
> > -----Original Message-----
> > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
> > Behalf Of Richard Heyes
> > Sent: Thursday, September 25, 2008 2:28 PM
> > To: Boyd, Todd M.
> > Cc: Frank Stanovcak; [EMAIL PROTECTED]
> > Subject: Re: [PHP] Filters and sanitizing a regexp
> >
> > > ...
> >
> > Hi,
> >
> > Had to have a play with this. Here's my (somewhat stricter) regex:
> >
> > preg_match('/((?:[0-3]?[0-9])?\d)-([0-1]?\d)-20\d\d/', '31-12-2000',
> > $matches);
> > if (!empty($matches[1]) AND $matches[1] > 31) $matches = array();
> > if (!empty($matches[2]) AND $matches[2] > 12) $matches = array();
> >
> > You could probably do the checks for the day and month within the
> > regex, but it's late :-)
>
> I don't think that one is quite right... Your optionals (?) are
> confusing. Why [0-3]?[0-9] AND the \d? Why [0-9] at all (since \d is
> essentially [0-9])? Why use the discarded capture group (?:) since the
> [0-3] is already optional?
>
> It's on! :D
>
> <?php
> $var = "as12/32/2000df";
> $matches = array();
> preg_match('#(\d?[0-9])\D*([0-3]?\d)\D*(\d{4})#', $var, $matches);
> if(count($matches) != 4 || $matches[1] > 12 || $matches[2] > 31)
> $matches = NULL;
> ?>
>
> MMDDYYYY 4 life, yo! Although, I would honestly prefer it if the world
> went to YYYYMMDD as a standard. Just seems to sort itself out more
> intuitively to the way I perceive time.
>
> (FYI, I'm not sure about the if() statement working out or not... I'm
> assuming PHP will drop through to the "then" part if there aren't 4
> elements in the array instead of arbitrarily testing the
> possibly-missing elements... but I didn't test that part.)
>
> Also, I used \D* to save space (and confusion). You could just as easily
> use (?:-|/) for hyphens or slashes.
>
>
> Todd Boyd
> Web Programmer
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
my contribution
/^\d{1,2}(\/)\d{1,2}(\/)\d{4}$/
--
Bastien
Cat, the other other white meat
--- End Message ---
--- Begin Message ---
Greetings, It flance.
In reply to Your message dated Thursday, September 25, 2008, 0:21:59,
>> > > -----Original Message-----
>> > > I am working on the code of a former employee and
>> I don't understand
>> > > what this $arr['N']['#'] refers
>> to.
>> > >
>> > > I know it is a multidimensional associative array
>> but the # i don't
>> > > what this means.
>> >
>> > '#' is just a string value.
>> >
>> > It has no special meaning whatsoever.
>>
>>
>> except in the deranged world of the original author :D
> You're right. Because associative arrays are meant to make code easier to
> understand by using meaningful indexes.
That, actually, COULD be meaningful index. In some cases.
Please don't top post any more. thank you.
--
Sincerely Yours, ANR Daemon <[EMAIL PROTECTED]>
--- End Message ---
--- Begin Message ---
Ashley Sheridan schreef:
> On Wed, 2008-09-24 at 21:45 -0400, Eric Butera wrote:
>> On Wed, Sep 24, 2008 at 9:22 PM, Shelley <[EMAIL PROTECTED]> wrote:
>>> 2008/9/25 Philip Thompson <[EMAIL PROTECTED]>
>>>
>>>> On Sep 24, 2008, at 7:29 AM, Maciek Sokolewicz wrote:
>>>>
>>>> tedd wrote:
>>>>>> At 12:25 PM +0100 9/24/08, Ashley Sheridan wrote:
>>>>>>
>>>>>>> On Wed, 2008-09-24 at 09:20 +0800, Shelley wrote:
>>>>>>>
>>>>>>>> <
>>>>>>>> http://phparch.cn/index.php/php/34-php-basics/202-the-data-literacy-test
>>>>>>>>> The
>>>>>>>> Data Literacy Test:
>>>>>>>>
>>>>>>>>
>>>>>>>> http://www.phparch.cn/index.php/php/34-php-basics/202-the-data-literacy-test
>>>>>>>>
>>>>>>>> What the smeg is this?
>>>>>> I don't know, but I figure 27.
>>>>>> Cheers,
>>>>>> tedd
>>>>>>
>>>>> yes, I think 27 aswell...
>>>>>
>>>>> - Tul
>>>>>
>>>> No no no. We all know the answer is 42.
>>>>
>>>> ? How come 42?
>>>
>>> --
>>> With best regards,
>>> Shelley Shyan
>>> http://phparch.cn
>>>
>> The question can't exist in the same universe as the answer. :(
>>
> But 42 is THE answer ;)
yes indeed, it's the answer to life, the universe and everthing.
oh crap, I just gave it away. as penance the next time a strange asks
me directions I'm gonna just say "42".
>
> Ash
> www.ashleysheridan.co.uk
>
>
--- End Message ---