大家好,我是 php 世界的新手,还在学习,我完全迷路了。我已经尝试了一切并阅读了很多博客,但没有什么能帮助我弄清楚如何去做。我有这段代码(下面),它工作得很好..它把一个长列表分成 5 个元素的块,这要归功于<ul>
& <li>
。
<?php
$values = range(1, 31);
$rows = array_chunk($values, 5);
foreach ($rows as $row) {
print "<ul>";
foreach ($row as $value) {
print "<li>" . $value . "</li>";
}
print "</ul>";
}
?>
但是当我尝试将它与我的其他代码(如下)合并时,它停止工作。它只显示<ul>
's,没有数据放入<li>
's甚至不显示。
<?php
$product = Mage::getModel('catalog/product');
$attributes = Mage::getResourceModel('eav/entity_attribute_collection')
->setEntityTypeFilter($product->getResource()->getTypeId())
->addFieldToFilter('attribute_code', 'manufacturer');
$attribute = $attributes->getFirstItem()->setEntity($product->getResource());
$manufacturers = $attribute->getSource()->getAllOptions(false);
?>
<ul>
<?php foreach ($manufacturers as $manufacturer): ?>
<li>
<a href="/manufacturer/<?php echo $manufacturer['label'] ?>">
<?php echo $manufacturer['label'] ?>
</a>
</li>
<?php endforeach; ?>
</ul>
这是我尝试过的变体之一(没有显示 500 错误的变体)
<?php
$rows = array_chunk($manufacturers, 5);
foreach ($manufacturers as $manufacturer) {
echo "<ul>";
foreach ($row as $manufacturer) {
echo "<li>" ?>
<a href="/manufacturer/<?php echo $manufacturer['label'] ?>"><?php echo $manufacturer['label'] ?></a>
<?php echo "</li>"; ?>
<?php }
echo "</ul>";
}
?>
我可能知道我正在做的事情是完全错误的,但正如我所说,我还是新手(我知道我还有很长的路要走。)
任何帮助都将不胜感激。先感谢您!
编辑:数组([value] => 15 [label] => Jordan)数组([value] => 19 [label] => Maison Scotch)数组([value] => 5 [label] => Museum)数组( [value] => 17 [label] => Nike ) Array ( [value] => 16 [label] => Nike Basket ) Array ( [value] => 11 [label] => On Tour ) Array ( [value] => 7 [label] => PeB ) Array ( [value] => 14 [label] => Penfiled ) Array ( [value] => 4 [label] => 总统的 ) Array ( [value] => 23 [label ] => Scotch & Soda ) Array ( [value] => 12 [label] => Solovair ) Array ( [value] => 13 [label] => Supra ) Array ( [value] => 20 [label] => Vans ) Array ( [value] => 18 [label] => Wood Wood )