Jump to content

[SOLVED] strange loop results


simon551

Recommended Posts

Hi, I'm trying to execute this foreach loop on a query. I have tested the query outside of php and it returns 2 records. But with the code I am using here, it is returning the first record, but twice. Not sure what I'm doing wrong.

  </tr>
    <?php  
//start new Show if recordset not empty 
 if ($totalRows_rsERDets_Amex2 > 0) { 
	 ?>
    <?php 
//start repeat region for 
do { 
?>
  <tr>
    <td><?php echo $row_rsERDets_Amex2['fdate']; ?></td>
    <td><?php echo $row_rsERDets_Amex2['ItemName']; ?></td>
    <td><?php echo $row_rsERDets_Amex2['vendor']; ?></td>
    <td><?php echo $row_rsERDets_Amex2['Description']; ?></td>
    <td><?php echo $row_rsERDets_Amex2['Project']; ?></td>
    <td><?php echo $row_rsERDets_Amex2['amtForeign']; ?></td>
    <td><?php echo $row_rsERDets_Amex2['amtUS']; ?></td>
    <td><?php echo $row_rsERDets_Amex2['PERS']; ?></td>
    <td>edit</td>
    <td>split</td>
  </tr>
    <?php 
//end repeat
} 
	while ($totalRows_rsERDets_Amex2 = mysql_fetch_assoc($rsERDets_Amex2)); 
?>

    <?php 
} 
// End Show if recordset not empty statement
	 ?>
</table>

Link to comment
https://forums.phpfreaks.com/topic/52541-solved-strange-loop-results/
Share on other sites

Change the loop to a "while" statement:

<?php
while ($totalRows_rsERDets_Amex2 = mysql_fetch_assoc($rsERDets_Amex2)) { 
?>
  <tr>
    <td><?php echo $row_rsERDets_Amex2['fdate']; ?></td>
    <td><?php echo $row_rsERDets_Amex2['ItemName']; ?></td>
    <td><?php echo $row_rsERDets_Amex2['vendor']; ?></td>
    <td><?php echo $row_rsERDets_Amex2['Description']; ?></td>
    <td><?php echo $row_rsERDets_Amex2['Project']; ?></td>
    <td><?php echo $row_rsERDets_Amex2['amtForeign']; ?></td>
    <td><?php echo $row_rsERDets_Amex2['amtUS']; ?></td>
    <td><?php echo $row_rsERDets_Amex2['PERS']; ?></td>
    <td>edit</td>
    <td>split</td>
  </tr>
    <?php 
//end repeat
} 
?>

 

Ken

 

 </tr>
   <?php  
//start new Show if recordset not empty 
 if ($totalRows_rsERDets_Amex2 > 0) { 
	 ?>
   <?php 
//start repeat region for 
while ($totalRows_rsERDets_Amex2 = mysql_fetch_assoc($rsERDets_Amex2)) { 
?>
 <tr>
   <td><?php echo $totalRows_rsERDets_Amex2['fdate']; ?></td>
   <td><?php echo $totalRows_rsERDets_Amex2['ItemName']; ?></td>
   <td><?php echo $totalRows_rsERDets_Amex2['vendor']; ?></td>
   <td><?php echo $totalRows_rsERDets_Amex2['Description']; ?></td>
   <td><?php echo $totalRows_rsERDets_Amex2['Project']; ?></td>
   <td><?php echo $totalRows_rsERDets_Amex2['amtForeign']; ?></td>
   <td><?php echo $totalRows_rsERDets_Amex2['amtUS']; ?></td>
   <td><?php echo $totalRows_rsERDets_Amex2['PERS']; ?></td>
   <td>edit</td>
   <td>split</td>
 </tr>
   <?php 
//end repeat
} 
?>

   <?php 
} 
// End Show if recordset not empty statement
	 ?>
</table>

 

Remember to call the RIGHT variable names.

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.