Page 1 of 1

[Solved] Nesting do loops

Posted: Sun Aug 21, 2005 2:52 am
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

Posted: Sun Aug 21, 2005 4:39 am
by feyd
any loop structure can be nested inside another.

provided you had the first record return for each query, it should basically work.

Posted: Sun Aug 21, 2005 5:58 am
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");
}
}

Posted: Sun Aug 21, 2005 11:40 am
by Addos
Thanks very much for your help. I have managed to get a solution to this problem.
Much appreciated your time folks.
B