Jump to content

[SOLVED] Help with Query


savagenoob

Recommended Posts

I can do that, I have another table that has the same data called members and the row member_id is the same as Employee.

How do I do it... foreach? can i get a snippet of how?

Here is how I tried but failed miserably...

<?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 $echo $myrow['Time']?></th>
    <th width="130" scope="col"> </th>
  </tr>
</table>
<?php
}
}
?>

Link to comment
Share on other sites

I am not quite sure that you are trying to do but in the sense that you are using this foreach it is pretty much pointless. take out the foreach and change the $show to $employee. So it is like this:

 

<?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'];

?>
<table width="700" border="0">
  <tr>
    <th width="179" scope="col"><?php echo $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 $echo $myrow['Time']?></th>
    <th width="130" scope="col"> </th>
  </tr>
</table>
<?php
}
?>

 

You said that you failed miserably can you give a little more information. What did not work that was supposed to work.

Link to comment
Share on other sites

Figured it out...below is code.

 

<?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.