如何划分零件阵列(不使用多维数组)用PHP? [英] How to divide array in parts (without using multidimensional arrays) with php?
本文介绍了如何划分零件阵列(不使用多维数组)用PHP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要把内容在的jQuery
滑块和滑块每张幻灯片是一个<李>
元素,我必须把该幻灯片中的产品列表,而且还当它是完全必须自动创建一个新的幻灯片。
I need to put content in a jquery
slider and for the slider each slide is a <li>
element and I have to put a list of products within that slide, but it also must automatically create a new slide when it's full.
现在我已经决定,我打算把4个元素在1幻灯片的疆打完4个元素,php的循环必须创建一个新的幻灯片。我该怎么办呢?它看起来有点像这样的:
Now I've decided that I'm going to put 4 elements in a boundry of 1 slide so after 4 elements, the php loop must create a new slide. How can I do that? It looks somewhat like this:
while($r=mysql_fetch_array($sql)) {
echo "
<li>
$r['title']
<li>";
}
但当然,这code创建一个新的幻灯片,每次返回的结果,这不是我想要的。
but of course, this code creates a new slide everytime it returns the result, which isn't what I want.
推荐答案
你可以试试这个
<?php
$count=4;
while($r=mysql_fetch_array($sql)) {
if($count % 4==0)
{
echo "<li>";
}
echo $r['title'];
if($count % 4 ==3)
{
echo "</li>";
}
$count++;
}
?>
这篇关于如何划分零件阵列(不使用多维数组)用PHP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文