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


?>

No comments posted yet

Your Answer:

Login to answer
322 Like 54 Dislike
Previous forums Next forums
Other forums

Why does my php page download images over and over
Can anybody please explain to me why my php page keeps downloading the images and other items every

SWF image using php?
Hello once again.

My latest en devour requires me to produce an image of a static .swf that i

Change Sort Order to Display Newest File First
Hi Guys,

I have a page that sorts the contents (PDFs) of a directory and displays them on the

Need help with PHP/MySQL drop down menu
I need help on how I can implement a drop down menu which queries mysql database and output the avai

Problem with umlauts and UTF-8
Hello every1,

I'm creating my own little CMS at the moment and got some problems with the cha

Will this protect from mysql injection?
I do not want anything like DROP TABLE to work or any type of coding..

Heres my code.. is it

switch form actions? not working
i want on submit to go to different pages according to the CatID

Code: <?php $CatID=$_

Need help with basic sql
Hi,

I am using oracle 10g, and having some small doubts related to sql , here goes the si

GMail like Chat in ASP.NET
Hi,Can anyone suggest me, how to incorporate GMail like chat in my existing ASP.Net application.I wa

Accessing Infotype data in dialog program
Hi All
In Dialog programs attributes I didn't see any logical database field. How can I access

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