close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Repeat loop within another repeat loop.

Thread began 5/27/2016 12:05 pm by joerg431091 | Last modified 5/31/2016 9:02 am by Ray Borduin | 780 views | 2 replies |

joerg431091

Repeat loop within another repeat loop.

How can I do a repeat within another repeat?

I have a repeat loop for available product sizes in my product_details.php page which works great. It checks whether there are attribute sizes available for this particular product and if so, loops and displays those option names on the product_details.php page.

Here is the code for that:

<!--### Available SIZES ###-->
<?php if ($row_WADAproducts['ProductAttributeSize'] == '1') { ?>
<div class="clearfix">
<label class="pull-left">Sizes:</label>
<?php do { ?>
<?php echo $row_rsSize_2['OptionName']; ?> /
<?php } while ($row_rsSize_2 = mysql_fetch_assoc($rsSize_2)); ?>
</div>
<?php }?>



I like to display the same information also on the product_results.php page.

My challenge is that, in the products_results.php page, this repeat loop nests within another repeat loop that displays each individual product on the category page.

So when I simply paste the repeat and the recordset from the products_detail.php page into the products_results.php page = it only shows the option names of the first product on the page but not for the rest.

What do I have to change to make this work?

Here is my code for this portion of the products_result.php page:



<!-- ### START PRODDUCT DISPLAY ###-->
<?php do { ?>
<article class="col-xs-12 col-sm-12 col-md-4 col-lg-4 text-center">
<div class="product">
<figure class="figure-hover-overlay">
<a href="products_detail.php?ProductID=<?php echo($row_WADAproducts['ProductID']); ?>&SubCatID=<?php echo($row_rs_SubCategories['SubCatID']); ?>&CategoryID=<?php echo($row_rs_Categories['CategoryID']); ?>" class="figure-href"></a>
<img src="/images/products/<?php echo($row_WADAproducts['ProductImage']); ?>" alt="Image" class="img-responsive">
<span class="bar"></span>
<figcaption>
<a href="products_detail.php?ProductID=<?php echo($row_WADAproducts['ProductID']); ?>&SubCatID=<?php echo($row_rs_SubCategories['SubCatID']); ?>&CategoryID=<?php echo($row_rs_Categories['CategoryID']); ?>" class="shoping"><i class="glyphicon glyphicon-eye-open"></i></a>
</figcaption>
</figure>
<div class="product-caption">
<div class="product-name-2"><a href="products_detail.php?ProductID=<?php echo($row_WADAproducts['ProductID']); ?>&SubCatID=<?php echo($row_rs_SubCategories['SubCatID']); ?>&CategoryID=<?php echo($row_rs_Categories['CategoryID']); ?>" ><?php echo(isset($_GET["pageNum_WADAproducts"])?"&pageNum_WADAproducts=".intval($_GET["pageNum_WADAproducts"]):""); ?> <?php echo($row_WADAproducts['ProductName']); ?></a>
p class="product-name"><strong>
<?php if ($row_WADAproducts['ProductAttributeSize'] == '') echo $row_WADAproducts['ProductSize']; ?>
</strong> </p>
</div><span class="alert-success"><?php echo $row_WADAproducts['ProductPromoText']; ?><?php echo $row_WADAproducts['ProductPromoCode']; ?></span>




<!-- START OPTION NAME REPEAT -->

<?php if ($row_WADAproducts['ProductAttributeSize'] == '1') { ?>
<?php do { ?>
<?php echo $row_rsSize_2['OptionName']; ?> /
<?php } while ($row_rsSize_2 = mysql_fetch_assoc($rsSize_2)); ?><p class="custom_product_info">starting at only:</p>
<?php } ?>

<!-- END OPTION NAME REPEAT -->



<p class="product-price"><span><?php echo $row_WADAproducts['ProductSRP']; ?></span> $<?php echo $row_WADAproducts['ProductPrice']; ?></p>
<div class="product-specials">
<div class="stars">
<table width="90%" border="0" cellspacing="2" cellpadding="2" align="center">
<tr>
<?php if ($row_WADAproducts['ProductPrice'] > '99') { ?><td><div align="center"><img src="images/Icons/FreeShipping50x50.png" width="35" height="35" /></div></td><?php } ?>
<?php if ($row_WADAproducts['ProductFreeBonus'] == '1') { ?><td><div align="center"><img src="images/Icons/FreeBonus50x50.png" width="35" height="35" /></div></td><?php } ?>
<?php if ($row_WADAproducts['ProductSRP'] != '') { ?><td><div align="center"><img src="images/Icons/OnSale50x50.png" width="35" height="35" /></div></td><?php } ?>
</tr>
</table>
</div>
</div>
</div>
</div>
</article>
<?php } while ($row_WADAproducts = mysql_fetch_assoc($WADAproducts)); ?>
<!-- ### END PRODDUCT DISPLAY ###-->

Any pointers are appreciated.

Thanks a lot,

Joerg

Sign in to reply to this post

Ray BorduinWebAssist

Usually you would need to also copy and paste to move your recordset inside of the outer loop as well so that it will get the associated rows. Try moving the options recordset into the outer loop and make sure it is filtered by the recordset row that is repeated.

If you still have problems please attach the actual page to a reply to this post. It is much easier to debug and give advice when I can open the page in Dreamweaver and reference line numbers.

Sign in to reply to this post
Did this help? Tips are appreciated...

joerg431091

Perfect. That did the trick.

Thanks so much Ray!

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...