我有一个从查询生成的长列表,但我需要输出最多4个列表(4列),每个列表中最多17个结果(总共最多68个),因为有一个设置的高度和适合这个宽度,我是新的PHP所以我不知道从哪里开始。我希望这是有道理的!
<li class="dir">List title
<?php
// The following query gets all brands that appear in the mens categories and orders by manufacturer name
$mens_categories_products_query = "SELECT * FROM `products_to_categories` `pc` ";
$mens_categories_products_query .= "LEFT JOIN `products` `pr` ON `pc`.`products_id` = `pr`.`products_id` ";
$mens_categories_products_query .= "LEFT JOIN `manufacturers` `mn` ON `pr`.`manufacturers_id` = `mn`.`manufacturers_id` ";
$mens_categories_products_query .= "WHERE `pc`.`categories_id` IN (";
$mens_categories_products_query .= substr($mens_categories_products_ids, 0, strlen($mens_categories_products_ids)-1);
$mens_categories_products_query .= ") GROUP BY `pr`.`manufacturers_id` ORDER BY `mn`.`manufacturers_name`";
//$mens_manufacturers_query = tep_db_query("SELECT * FROM `manufacturers` ORDER BY `manufacturers_name` ASC;");
// Run the new query
$mens_manufacturers_query = tep_db_query($mens_categories_products_query);
$mens_manufacturers_list = "";
while ($mens_manufacturers = tep_db_fetch_array($mens_manufacturers_query)) {
$mens_manufacturers_list .= '<li><a href="' . tep_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . $mens_manufacturers['manufacturers_id']) . '">' . $mens_manufacturers['manufacturers_name'] . '</a></li>';
}
echo "<ul>$mens_manufacturers_list</ul>";
?>
</li>
答案 0 :(得分:1)
也许是这样的?
$i = 1;
print "<ul>";
while ($mens_manufacturers = tep_db_fetch_array($mens_manufacturers_query)) {
if ($i % 17 == 1) {
print "<ul>";
}
if ($i == 68) {
print '<li><a href="readmore.php">Read more</a></li>';
}
else {
print '<li><a href="' . tep_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . $mens_manufacturers['manufacturers_id']) . '">' . $mens_manufacturers['manufacturers_name'] . '</a></li>';
}
if ($i % 17 == 0) {
print "</ul>";
}
$i++;
}
使用类似
的CSSul {
width: 21%;
float: left;
}
更新:
更新代码以更正第一个<ul>
上的编号循环。在第68个条目中添加了“阅读更多”链接。
答案 1 :(得分:0)
尝试添加增量变量,在17行添加另一个ul
$i = 0;
$mens_manufacturers_list = '<ul>';
$dbresult = tep_db_fetch_array($mens_manufacturers_query);
while ($mens_manufacturers = $dbresult) {
$i++;
$mens_manufacturers_list .= '<li><a href="' . tep_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . $mens_manufacturers['manufacturers_id']) . '">' . $mens_manufacturers['manufacturers_name'] . '</a></li>';
if($i%17==0){
$mens_manufacturers_list .= '</ul>';
}
if(count($dbresult) < $i){
$mens_manufacturers_list .= '<ul>';
}
}
echo $mens_manufacturers_list;
答案 2 :(得分:0)
<?php $i = 1;
echo "<li class=\"dir\">BRANDS<ul>";
$skate_manufacturers_query = tep_db_query($skate_categories_products_query);
while ($skate_manufacturers = tep_db_fetch_array($skate_manufacturers_query)) {
if ($i % 17 == 0)
echo "</ul></li><!-- start col --><li class=\"dir\"> <ul>";
echo '<li><a href="' . tep_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . $skate_manufacturers['manufacturers_id']) . '">' . $skate_manufacturers['manufacturers_name'] . '</a></li>';
if ($i % 18 == 0)
echo "<!-- end one col -->";
$i++;
} ?>
</ul> <!-- needs these added -->
</li> <!-- needs these added -->