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
https://forums.phpfreaks.com/topic/177912-solved-array-loop-problem/
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 > -->


?>

My problem is that the data generated from the SQL is not being displayed.  I know there's data there because I tested it.  It should loop though and provide me with the output from the HoursWorked field that is created in the SQL statement.  There are no errors in the sql syntax (i checked).

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?

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.