我有类别表,里面包含35个类别。我希望他们在一个while循环中进入四个div。
<?php
$count = 0;
$cat = pullcategories();
$catcount = mysqli_num_rows($cat);
$percat = ceil($catcount / 4);
$topcats = pulltopcategories($count, $percat);
//same with pullcategories, just LIMIT $count,$per //
while ($topcats = mysqli_fetch_object($topcats)) {
?>
<div class="col3">
<ul class="list-unstyled list-dashed">
<li>
<a href="">$topcats->title</a>
</li>
</ul>
</div>
<?php
$count = $count + $percat;
$percat = $percat * 2;
}
?>
答案 0 :(得分:0)
$count = 0;
$cat = pullcategories();
$catcount = mysqli_num_rows($cat);
$percat = ceil($catcount / 4);
$topcats = pulltopcategories($count, $percat);
这会将您的列表分为4个部分,您需要调用“$ topcats = pulltopcategories($ count,$ percat);” 4次能够通过所有数据。
我会把它改成这样的东西。 假设“pulltopcategories($ count,$ percat)”使用count作为限制,而percat作为SQL中的偏移量应该有效。
请尝试让我知道 - 我可以解决任何错误(如果有的话)(我的PHP有点生疏,我没有数据可以尝试这个)
<?php
$count = 0;
$cat = pullcategories();
$catcount = mysqli_num_rows($cat);
$percat = ceil($catcount / 4);
while ($count < catcount){ /* Loop until you have finished all cats */
$topcats = pulltopcategories($count, $percat);
echo "<div class="col3">
<ul class='list-unstyled list-dashed'>";
while ($topcats = mysqli_fetch_object($topcats)) {
echo "<li>
<a href=''>$topcats->title</a>
</li>"
}
echo "</ul>
</div>";
$count = $count + $percat;
}
?>