Help - Search - Members - Calendar
Full Version: What's wrong?
Invision Power Services > Community Forums > Community Web Design and Coding
Watty
Can someone tell me why this won't process correctly?

CODE
function elapsedtime($sec) {
    $days  = floor($sec / 86400);
    $hrs   = floor(bcmod($sec,86400)/3600);
    $mins  = round(bcmod(bcmod($sec,86400),3600)/60);
    if ($days > 20)
        $tstring = $days . "d ";
    if ($hrs  > 0)
        $tstring.=$hrs . " hours ";
    if ($mins>0) {
        if ($mins<10 && $hrs>0)
            $tstring.="0";
        $tstring.=$mins . " minutes";
    }
    return $tstring;
}

// Make the query.
$query = "SELECT * FROM timesheet WHERE username = '$username' ORDER BY date";
$result = @mysql_query ($query); // Run the query.

/* read the beginning and end times in from the database prior to this*/
$et = elapsedtime(($row['lunch'] - ($row['clockin']) + ($row['clockout'] - ($row['back_lunch']))));

echo "<center><b><font color = 'blue'>Timecard display for $username</font></center></b><br>";

// Table header.
echo '<table align="center" cellspacing="0" cellpadding="5">
<tr>
<td align="left"><b>Date</b></td>
<td align="left"><b>Clock in:</b></td>
<td align="left"><b>Out to lunch:</b></td>
<td align="left"><b>Back from lunch:</b></td>
<td align="left"><b>Clock out:</b></td>
<td align="left"><b>Total hours for the day:</b></td>
</tr>';


// Fetch and print all the records.
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
    print <<<EOF
    <tr>
    <td align="left">{$row['date']}</td>
    <td align="left">{$row['clockin1']}</td>
    <td align="left">{$row['lunch1']}</td>
    <td align="left">{$row['back_lunch1']}</td>
    <td align="left">{$row['clockout1']}</td>
    <td align="left">$et</td>[/b]
    </tr>
EOF;
}

echo '</table>';

mysql_free_result ($result); // Free up the resources.

mysql_close(); // Close the database connection.


I'm guessing the $et variable won't display because it's not data that is kept in the database, but I'm not sure.

Dagur
shouldn't you be calculating $et in the loop?
Watty
Bingo... that did the trick. w00t.gif

thumbsup.gif
int2str
What if the person didn't go to lunch?

To further comment:

I wouldn't even bother with the special "lunch" case. Instead, I'd only have two functions "Clock in" and "Clock out". When you go to lunch you "Clock out" - no need to state why. That way you instantly handle the case of the afternoon coffee run as well.

Then you just tally up the hours per day.

Keep it simple....
Watty
QUOTE(int2str @ Apr 21 2006, 10:28 AM) *
What if the person didn't go to lunch?

To further comment:

I wouldn't even bother with the special "lunch" case. Instead, I'd only have two functions "Clock in" and "Clock out". When you go to lunch you "Clock out" - no need to state why. That way you instantly handle the case of the afternoon coffee run as well.

Then you just tally up the hours per day.

Keep it simple....


Already accounted for that. original.gif I added an IF statement handling the time if they didn't clock out for lunch. Then it simply subtracts the clockout time from the clockin time.

I have the clock out for lunch button just to make it more user friendly/appealing. Nothing but austhetics.
Brandon C
Not to be the least bit nosy tongue.gif, but what's this going to be for Craig? And are you going to put up a test site for us to check it out, or would you prefer it to be private? original.gif
Starnox
It's for his workplace.
Brandon C
QUOTE(Starnox @ Apr 21 2006, 04:44 PM) *
It's for his workplace.

Ahh, OK.
Watty
QUOTE(Brandon C @ Apr 21 2006, 02:35 PM) *
Not to be the least bit nosy tongue.gif, but what's this going to be for Craig? And are you going to put up a test site for us to check it out, or would you prefer it to be private? original.gif


Yep, just a little something I'm doing for work. The boss was getting concerned about people lying about their times (we were using another time card script by the name of OATS, but it allows peeps to manually enter their times)... so he asked me to come up with something so they CAN'T enter their own times.

Yea, I'll probably throw it up as a test/demo so other folks can check it out - or even to make suggestions/improve the code. My wifes work has shown some interest in it as well - but their servers are down more often than not, so it wouldn't be too feasible for them. laughing.gif

Got a few more things to figure out (which is cryptic for meaning I'll be asking for help here if/when I get stuck (yet again)). wassat.gif

I'll make some simple screenies available later tonight or early tomorrow for the heck of it. Like I said - it's simple. original.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.