donglengli0644 2011-04-08 13:22
浏览 32
已采纳

PHP循环有助于添加非循环数据

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
Product
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; ?>
  • 写回答

1条回答 默认 最新

  • dongyang4615 2011-04-08 13:29
    关注
    <?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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大