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

 

Link to comment
Share on other sites

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

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.