[Solved] Nesting do loops

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Addos
Forum Contributor
Posts: 305
Joined: Mon Jan 17, 2005 4:13 pm

[Solved] Nesting do loops

Post by Addos »

Can anyone tell me if this should work or not? I’m very puzzled about whether or not I can have a ‘do’ Loop nested. I have read that ‘for’ loops can but I can’t seem to get a ‘for’ loop to work in the script below.

Thanks a mil
B

Code: Select all

<?php  do {  ?>
<table width="100%"  border="0" cellpadding="0" cellspacing="0" class="tblproperty">
  <tr>
    <td>
<table width="100%"  border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td class="tblbg">Description</td>
  </tr>
   <tr>
    <td><?php echo nl2br($row_getProperties['description']); ?></td>
  </tr>
  <tr>
   <td class="tblbg">Prices</td>
  </tr>
  <tr>
    <td><?php echo nl2br($row_getProperties['prices']); ?></td>
  </tr>
</table>
</td>
  </tr>
  <tr>
    <td>
<?php do { 
	
	if (isset($row_rstThumbs['ThumbName']) && file_exists('images/apartments/'.$row_rstThumbs['ThumbName'])) {
  	 $image_info_1 = getimagesize('images/apartments/'.$row_rstThumbs['ThumbName']);
  	 }$dims_1 = isset($image_info_1) ? $image_info_1[3] : '';
	
	if (isset($row_rstThumbs['ImageName']) && file_exists('images/apartments/'.$row_rstThumbs['ImageName'])) {
  	 $image_info_large = getimagesize('images/apartments/'.$row_rstThumbs['ImageName']);
  	 }$dims_2 = isset($image_info_large) ? $image_info_large[3] : '';
	echo $row_rstThumbs['id']; 
	if ($dims_1)  { ?> 									
	 <a href="gallery_pop.php?image_id=<?php echo $row_rstThumbs['id']; ?>" title="Mogan Puerto"><img src="images/apartments/<?php echo $row_rstThumbs['ThumbName']; ?>" <?php echo $dims_1; }?>  alt="Click for a larger image" border="0" onClick="dpSmartLink('gallery_pop.php?image_id=<?php echo $row_rstThumbs['id']; ?>','newWin','<?php echo $image_info_large[0]+ '20'; ?>','<?php echo $image_info_large[1]+ '50'; ?>','100:0',0);return document.MM_returnValue"></a>
     <?php } while ($row_rstThumbs = mysql_fetch_assoc($rstThumbs)); ?>
  		</td>
  </tr>
</table>
 <?php  } while ($row_getProperties = mysql_fetch_assoc($getProper
Last edited by Addos on Sun Aug 21, 2005 11:40 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

any loop structure can be nested inside another.

provided you had the first record return for each query, it should basically work.
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

this is how a for loop is used to extract db records

Code: Select all

$query = "select `name`, `email`,`phone` from table_name";
$result = mysql_query($query);
if (is_resource($result)){
$rows = mysql_num_rows($result);
for ($i=0;$i<$rows;$i++){
echo mysql_result($result, $i, "name");
echo mysql_result($result, $i, "email");
echo mysql_result($result, $i, "phone");
}
}
Addos
Forum Contributor
Posts: 305
Joined: Mon Jan 17, 2005 4:13 pm

Post by Addos »

Thanks very much for your help. I have managed to get a solution to this problem.
Much appreciated your time folks.
B
Post Reply