mike305 Posted March 2, 2009 Share Posted March 2, 2009 I am looking for some help with a php problem. (I found this forum on google) and was hoping someone in here would be able to help me out. I have a table here: Which list 1 row of 5 of the most recent products I have added to the Magento store. My goal is to get 2 rows of 5 products - to show 10 products all together. It seems simple im sure. But I do not know PHP that well. <?php if (($_products = $this->getProductCollection()) && $_products->getSize()): ?> <table id="new-products-list-table"> <tr> <?php $i=0; foreach ($_products->getItems() as $_product): ?> <?php if ($i>5): continue; endif; ?> <td> 5 items here </td> <?php $i++; endforeach; ?> <?php for($i;$i%5!=0;$i++): ?> <td class="empty"> </td> <?php endfor; ?> </tr> </table> <?php endif; ?> Above is just the summery of the code: I was trying to make it more readable on the eye. Here is the full phtml code. <?php if (($_products = $this->getProductCollection()) && $_products->getSize()): ?> <table id="new-products-list-table"> <tr> <?php $i=0; foreach ($_products->getItems() as $_product): ?> <?php if ($i>5): continue; endif; ?> <td> <?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?> <div class="compare"><a href="<?php echo $_compareUrl ?>"><?php echo $this->__('Compare Item') ?></a></div> <?php endif; ?> <a class="product-image" href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"><img class="product-image" src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(150, 150) ?>" width="150" height="150" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>" /></a> <h3 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>)"><?php echo $this->htmlEscape($_product->getName()) ?></a></h3> <?php echo $this->getReviewsSummaryHtml($_product, 'short') ?> <?php echo $this->getPriceHtml($_product, true, '-new') ?> <?php if($_product->isSaleable()): ?> <button class="button" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><?php echo $this->__('Add to Cart') ?></span></button> <?php else: ?> <p class="availability"><span class="out-of-stock"><?php echo $this->__('Out of stock') ?></span></p> <?php endif; ?> </td> <?php $i++; endforeach; ?> <?php for($i;$i%5!=0;$i++): ?> <td class="empty"> </td> <?php endfor; ?> </tr> </table> <?php endif; ?> Thank you for the help.. Quote Link to comment Share on other sites More sharing options...
WolfRage Posted March 3, 2009 Share Posted March 3, 2009 Sorry your code is confusing to me, but just add another row using <tr> code in here </tr> and continue your $i or counting variable for another 5 products. Hope that helps. Oh and in the future use the Code Brakets to highlight your code, makes it a hell of a lot easier to read then. Quote Link to comment Share on other sites More sharing options...
semaphorian Posted May 2, 2009 Share Posted May 2, 2009 yes the code is looking bit confusing Quote Link to comment Share on other sites More sharing options...
eonejames Posted May 1, 2013 Share Posted May 1, 2013 Your code still getting confused us so just check what the actual code you wants Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.