我已经构建了以下函数,但是是否可以让它将我的列表从一个拆分为多个,这样我每个最多可以有 8<li>
个<ul>
?
function buildProductsMenu($base) {
$sql = "SELECT *
FROM tbl_category";
$result = dbQuery($sql);
while ($row = dbFetchAssoc($result)) {
echo "<ul>";
echo "<li class='title'>$row[cat_name]</li>";
$sqlProd = "SELECT *
FROM tbl_product WHERE cat_id = $row[cat_id]";
$resultProd = dbQuery($sqlProd);
while ($rowProd = dbFetchAssoc($resultProd)) {
extract($rowProd);
echo "<li><a href='".$base."products/".strtolower($row['cat_name'])."/".strtolower($pd_name)."'>".$pd_name."</a></li>";
}
echo "</ul>";
}
}
与 jurgemaister 解决方案一起去
function buildProductsMenu($base) {
$sql = "SELECT *
FROM tbl_category";
$result = dbQuery($sql);
while ($row = dbFetchAssoc($result)) {
echo "<ul>";
echo "<li class='title'>$row[cat_name]</li>";
$sqlProd = "SELECT * FROM tbl_product WHERE cat_id = $row[cat_id]";
$resultProd = dbQuery($sqlProd);
$counter = 1;
while ($rowProd = dbFetchAssoc($resultProd)) {
extract($rowProd);
if($counter % 12 == 0) {
$counter = 1;
echo "</ul><ul style='margin-top:25px;'>";
}
echo "<li><a href='".$base."products/".strtolower($row['cat_name'])."/".strtolower($pd_name)."'>".$pd_name."</a></li>";
$counter++;
}
echo "</ul>";
}
}