Jump to content

[SOLVED] Table Help


savagenoob

Recommended Posts

OK, I know some of this involves MySQL but I posted over there a few days ago and got little help...

 

I have a table named timeclock with Employee, Clock, Timestamp for options. Is it possible to select the last row for each employee?

I am trying to build a table for an admin to view the last punch for each employee showing whether they are currently clocked in or out.

 

If there is not a way to do this with MySQL, how could I build some kind of loop to find the last unique value for Employee and display the row...

 

Here are the table headers... I am displaying a pin image under In or Out depending on whether or not the client is clocked in or out.

 

 

   

Employee

   

Out

   

In

   

Last Punch

   

Notes

 

 

Link to comment
Share on other sites

Heres my code that doesnt work

 

<?php
$agency = $_SESSION['SESS_AGENCY'];

$result = mysql_query("SELECT * FROM timeclock WHERE Agency = '$agency' ORDER BY Clock DESC LIMIT 1");
while($myrow = mysql_fetch_assoc($result))
{
$employee = $myrow['Employee'];
foreach ( $employee as $show )
{
?>
<table width="700" border="0">
  <tr>
    <th width="179" scope="col"><?php echo $show; ?></th>
    <th width="80" scope="col"><?php if ($myrow['Clock'] == "Out"){ echo "<img src=\"images/round_push_2.gif\" alt=\"Push Pin 2\" />"; }?>
</th>
    <th width="80" scope="col"><?php if ($myrow['Clock'] == "In"){ echo "<img src=\"images/round_push_1.gif\" alt=\"Push Pin 1\" />"; }?></th>
    <th width="209" scope="col"><?php $punchdate =strtotime($myrow['Time']); echo date("l, m/d/Y, g:i a", $punchdate); ?></th>
    <th width="130" scope="col"> </th>
  </tr>
</table>
<?php
}
}
?>

Link to comment
Share on other sites

ID Employee Time             Clock    Minutes  Agency

100 2 2009-01-17 22:50:15 In 1 (null)

101 2 2009-01-17 22:51:24 Out 1 (null)

102 2 2009-01-17 23:08:08 In 16 (null)

103 2 2009-01-17 23:11:19 Out 3 (null)

104 2 2009-01-18 00:07:24 In 56 (null)

105 2 2009-01-18 15:41:13 Out 933 (null)

106 2 2009-01-18 18:20:54 In 159 (null)

107 2 2009-01-29 22:31:36 Out 297 1 Solution Insurance

108 2 2009-01-29 22:31:36 In 643 1 Solution Insurance

109 2 2009-01-29 22:31:36 Out 244 1 Solution Insurance

110 2 2009-01-29 22:31:36 In 305 1 Solution Insurance

111 2 2009-01-29 22:31:36 Out 0 1 Solution Insurance

112 3 2009-01-30 00:40:11 In 0 1 Solution Insurance

113 3 2009-01-30 00:40:11 Out 0 1 Solution Insurance

114 2 2009-01-29 22:31:35 In 1338 1 Solution Insurance

115 2 2009-01-29 22:31:35 Out 1660 1 Solution Insurance

116 2 2009-01-29 22:31:35 In 10202 1 Solution Insurance

117 2 2009-01-29 22:31:35 Out 0 1 Solution Insurance

 

I might add that the Employee number is pulled from another table called members - member_id.

Link to comment
Share on other sites

I figured this out finally, thank god...

 

<?php
$agency = $_SESSION['SESS_AGENCY'];
$query = "SELECT * FROM members WHERE agency = '$agency'";
$sql = mysql_query($query);
while ($emp2  = mysql_fetch_array($sql))
{
$employee = $emp2['member_id'];

$result = mysql_query("SELECT * FROM timeclock WHERE Agency = '$agency' AND Employee = $employee ORDER BY Clock DESC LIMIT 1");
while($myrow = mysql_fetch_assoc($result))
{
?>
<table width="700" border="0">
  <tr>
    <th width="179" scope="col"><?php echo $myrow['Employee']; ?></th>
    <th width="80" scope="col"><?php if ($myrow['Clock'] == "Out"){ echo "<img src=\"images/round_push_2.gif\" alt=\"Push Pin 2\" />"; }?>
</th>
    <th width="80" scope="col"><?php if ($myrow['Clock'] == "In"){ echo "<img src=\"images/round_push_1.gif\" alt=\"Push Pin 1\" />"; }?></th>
    <th width="209" scope="col"><?php $punchdate =strtotime($myrow['Time']); echo date("l, m/d/Y, g:i a", $punchdate); ?></th>
    <th width="130" scope="col"> </th>
  </tr>
</table>
<?php
}
}
?>

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.