2011-04-10 169 views
0

我是新來的PHP,我試圖讓這個循環通過額外的LI的只要至少有8個更多的存在我已經嘗試過,並不能找出正確的方式來實現這一點。PHP迭代循環

<?php $model->getFeaturedVehicles(24, 0, unserialize($vtype), unserialize($makes), $p1range, $p2range, $filters) ?> 
<div id="slider"> 
    <ul> 
    <li> 
     <?php while ($unit = $model->iterate()): ?> 
     <div class="feature-vehicle" align="center"><a href="<?php echo DIR_REL,'/inventory/',$unit->url ?>"><img src="http://images.idealer1.com/getimage/90/<?php echo $unit->previewvpid ?>.jpg" alt="<?php echo $unit->description ?>" /></a> 
     <p><?php echo $unit->description ?></p> 
     </div> 
     <?php endwhile; ?> 
    </li> 
    <li>loop through 8 more if at least 8 more exist</li> 
    <li>loop through 8 more if at least 8 more exist</li> 
    </ul> 
</div> 
+1

你將需要向我們展示'iterate'的作用。如果循環沒有停止/從不開始,那麼該方法返回的可能有問題。 – 2011-04-10 19:47:36

回答

0

如果API不公開的方式來計算記錄的總數(包括獲得的剩餘記錄數組和計數那),你可以使用PHP output buffering functionsob_start等)將數據緩存在for循環中(計數爲8),並且僅在$i計數達到8或更多時纔打印結果。