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;">&nbsp;</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 -->


?>

322 Like 54 Dislike
Previous php-forum Next php-forum
Other php-forum

While Problem
i am having a problem with a while statement here is the code
Code: [Select]<?php
sess

calendar dates and hours compare problem
i have a calendar in wordpress, everything works great except that i can make 2 meetings at the same

Exporting new records
Trying to figure out the best way to set this up.

People register my site.

Their prof

Simultaneous select/update/insert
Hi

How would I need to go about when 2 users update a single row simultaneous? And how would

PHP Redirecting
Hello everyone. Is there a way to redirect people to pages within a statement in PHP? Since there is

Preg_match unknown modifyer
Hello,

Im trying to write a little script for my forums i need to get the reply from my forum

Something Non-Traditional. Can we solve?
I have an idea for an application here. It's mostly flash, but it couldn't work without a somewhat n

Reading waves
Hi,

I am trying to find a way of finding the highs and lows on a graph line, the line points

preg_replace question
Hello!!

I hope someone can help me with preg_replace.

I load two tables from an extern

PHP & Images [Resize, Crop, Save]
Hey! Well I have a little dilema, hoping I could find some guidance.

I have a CMS and on the

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash