开发者

PHP loop help addining non loop data

开发者 https://www.devze.com 2023-02-22 20:30 出处:网络
I have a PHP that loops through my best sellers, however I need to add in some point of sales in a certain pattern, and I have no idea how to do this,

I have a PHP that loops through my best sellers, however I need to add in some point of sales in a certain pattern, and I have no idea how to do this,

I need to do the following:

Product
Product
POS
POS
P开发者_如何学Goroduct
Product

How can I achieve this? Currently this is my PHP loop,

<?php foreach ($featured as $product) : ?>
    <?php if(isset($product->productId)) : ?>
        <li>
        <h3><strong>Best Seller</strong> <a href="#" title="View Dining"><?php echo $product->rangeTitle; ?></a></h3>
        <a class="catJump" title="View Dining" href="#">View Dining</a>
        <a class="pImageLink" title="Buy the Bistro Chair" href="#"><img width="242" height="130" title="6 Seater Cube Set" alt="6 Seater Cube Set" src="/assets/img/temp/bestseller.jpg" /></a>
        <span class="bestSale">
            <h4>6 Seater Cube Set<br /><em>was <strike>&pound;3995</strike> NOW &pound;2995</em></h4>
            <a class="quickview" href="#" title="View Details"><strong>SAVE 10%</strong> Click here</a>
        </span>
        </li>
    <?php endif; ?>
<?php endforeach; ?>


<?php 
    $i = 0;
    $j = 0;
    $product_count = count($featured);
    while ($j<$product_count) {
        if ($i==2 || $i==3) {
            echo "POS";
        } else {
            echo $featured[$j]->productId;
            ++$j;
        }

        ++$i;
        if ($i>3) $i = 0;
    }
?>

I let you replace the echo statements by what you want

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号