LOOPing Problem
Posted on
16th Feb 2014 07:03 pm by
admin
Hello All!
The following code loops through the data and displays the data accordingly. My problem is that the $listPR->HoursWorked; array repeats itself. The foreach($listLocations as $listLoc) loops and displays the locations but the data array for HourWorked doesn't change per location. I'm not sure that this is a MySQL question but here is the SQL Statement: I can't figure out where I would "break" the loop and start it again to display the information correctly per location? Can someone give me a hand on this one? Thanks for the help in advance!
Code: [Select]<?php
$locSql = "SELECT * FROM Location AS loc WHERE companyID=". $_SESSION['company_id'] ." AND (" . $selLoc . ")";
$listLocations = locData::find_by_sql($locSql);
$sql = "SELECT *,
DATE_FORMAT( Clockin, '%H:%i' ) AS FormattedTimeIn,
DATE_FORMAT( Clockout, '%H:%i' ) AS FormattedTimeOut,
TIMEDIFF( Clockout, Clockin ) AS HoursWorked
FROM time_clock AS tc
JOIN employees AS e ON e.Id = tc.Emp_id
JOIN location AS loc ON loc.LocationID = tc.LocationID
JOIN employmentdetail AS ed ON ed.UserId = e.Id
WHERE tc.Clockin BETWEEN '".$Date1."' AND '".$Date2."'
AND (" . $selLoc . ") AND ed.Active = 1
ORDER BY e.LastName ASC";
$listPayrollSum = mysql_query( $sql );
?>
And here is the loop that I'm having trouble getting to not duplicate the data:
Code: [Select]<?php
<!-- Loop thru and generate output -*** Based on Number of Employees and Number of Locations *** Some data may return NULL for location
foreach Loop < tr > # of Employee create table cells -->
<?php while( $listPR = mysql_fetch_object( $listPayrollSum ) ) { $row_count++; ?>
<tr class="grid-content"<?php if ($row_count%2) { ?> bgcolor="#ebebeb" <?php } ?> >
<td style="padding:5px;" ><?php echo $listPR->LastName. ", " .$listPR->FirstName ?></td>
<!-- foreach Loop < # of Locations > -->
<?php foreach($listLocations as $listLoc){ ?>
<td style="padding:5px; border-left:#333 1px solid;" align="center"> <?php echo $listPR->HoursWorked;?> </td>
<td style="padding:5px;" align="center">$2,400.80</td>
<td style="padding:5px;" align="center">$1,000</td>
<?php } ?>
<!-- End foreach Loop < Locations > -->
<!-- Total -->
<td align="center" style="border-left:#333 1px solid;"> </td>
<td align="center" style="padding:5px; border-left:#333 1px solid;" >2000</td>
<td align="center" style="padding:5px;" >$25,000.00</td>
<td align="center" style="padding:5px;" >$6,000,000.00</td>
</tr>
<?php } ?>
<!-- End Loop for Employee -->
?>
No comments posted yet
Your Answer:
Login to answer
322
54
Other forums
Conditions of info record - Error
When i created GR (901) and PO create automatic my PBXX is obtain the net price of info record but
classic dynpro : hide area and auto adjust hights
Hi,
I want to develop a similar user interface as is used in standard transaction MIGO.
subtract 1 from value entered in text field
Hi
How do I subtract 1 from the vaue entered into a text field?
Thanks
Mail form doesn't send Russian/Cyrillic characters correctly?
When someone enters foreign characters (like Cyrillic text, and Japanese/Chinese probably gives the
unserialize help, getting errors
hi all ,
I got a form with 6 fields (2 input and 4 select box), when the page loads one block is
void* and sizeof()
Hi,
Using void* and sizeof is it possible to get the value of the object ?
I understan
need to apply an if/else statement to Tim Thumb script
Not sure how to work this. I essentially want to call a variety of image sizes based on which style
Locking mysql tables with php
Hi
BACKGROUND:
I have multiple instances of the same php script running in a WAMP environ
Save data in input fields when they press "BACK BUTTON"
Hi, this is html form: And let's say they get a error "Please enter ur title must be more then
Encrypt php code?
Is it possible to encrypt php code in files,
so that it displays a load of unreadable characters