Jump to content

[SOLVED] Array Loop Problem


inspireddesign

Recommended Posts

Hello,

 

I have a small problem that can't seem to figure out.  The following code loops through the array and displays the information accordingly.  But my problem is that second echoed array doesn't get displayed.  I think it's getting overwritten?  Not sure.  Can some help me, please?  Thanks.

 

<?php

					      \<?php foreach($listLocations as $listLoc){ ?>
                                                                                                        
                                                  <td style="padding:5px; border-left:#333 1px solid;" align="center"> 

													  <?php 

													$locSql  = "SELECT *,  
												    			FLOOR(SUM(TIMEDIFF( Clockout, Clockin ))) AS HoursWorked 
																FROM time_clock AS tc
																WHERE tc.Clockin BETWEEN '".$Date1."' AND '".$Date2."' 
																AND tc.LocationID = " . $listLoc->LocationID . "
																AND tc.Emp_Id = " . $listPR->Id . " 
																GROUP BY tc.Emp_Id";	

													$Hours = mysql_query( $sql );
													$listHours = mysql_fetch_object( $Hours );

												   
												   echo $locSql;
													  
												   echo $listHours->HoursWorked;
												   
												   
												   
													  
													  ?> 
                                                   
                                                  </td>
                                                            
                                                  <td style="padding:5px;" align="center">$2,400.80</td>
                                                  <td style="padding:5px;" align="center">$1,000</td>

				<?php  } 


?>

Link to comment
Share on other sites

Here's all the code.  The SQL objects are getting displayed when i echo the the SQL statement.

 

<?php

							<?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->Id . " " . $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 

													$locSql  = "SELECT *,  
												    			FLOOR(SUM(TIMEDIFF( Clockout, Clockin ))) AS HoursWorked 
																FROM time_clock AS tc
																WHERE tc.Clockin BETWEEN '".$Date1."' AND '".$Date2."' 
																AND tc.LocationID = " . $listLoc->LocationID . "
																AND tc.Emp_Id = " . $listPR->Id . " 
																GROUP BY tc.Emp_Id";	

													$Hours = mysql_query( $sql );
													$listHours = mysql_fetch_object( $Hours );

												   
												   //echo $locSql;
													  
												   if( $listHours->HoursWorked == NULL ) { echo '0'; } else { echo $listHours->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 > -->


?>

Link to comment
Share on other sites

had you said this:

My problem is that the data generated from the SQL is not being displayed.
should've said this right off the bat.  gotta get right to the problem at hand.

 

this would be your culprit then:

 

$Hours = mysql_query( $sql );

 

should be:

 

$Hours = mysql_query( $locSql );

 

right?

Link to comment
Share on other sites

WOW... OMG!  I'm SO sorry.  You are right.  Damn.  Thanks.  :o

don't apologize .. you're looking for a larger problem because these kinds of mistakes are assumed correct.

 

next time, for yourself, work your way back from the problem, starting with the problem:  query is working (no errors), just not getting the results .. must check $variables, etc.

 

and be (as) short (as possible) and sweet with your problem .. when you eventually said:

 

My problem is that the data generated from the SQL is not being displayed.

 

i knew exactly where to look.

 

glad i could help.

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.