1

Hello everybody I'm new in the php world still learning, and I'm completely lost. I've tried everything and read a lot of blogs but nothing helps me to figure out how to do it. I have this code (below) which works perfectly.. it's dividing a long list in blocks of 5 elements, thanks to <ul> & <li>'s.

<?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>";
}
?>

But When I try to merge it together with my other code (below), it stops to work. It only displays the <ul>'s and no data is putted in <li>'s which don't even display.

<?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>

This is one of the variants I've tried (the one that doesn't show me a 500 error)

<?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>";
}
?>

I know probably what I'm doing is completely wrong, but as I said I'm new still learning (I have a long way to go, I know.)

Any help will be more than appreciate. Thank you in advance!

EDITS: Array ( [value] => 15 [label] => Jordan ) Array ( [value] => 19 [label] => Maison Scotch ) Array ( [value] => 5 [label] => Museum ) Array ( [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] => President's ) 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 )

3
  • 1
    What is in the $manufacturer variable? Please put this line just after your foreach loop: print_r($manufacturer);. Thanks. Commented Dec 17, 2012 at 14:58
  • Learn to monitor your servers log files, especially the error log file. You gain valuable hints on what is wrong. Commented Dec 17, 2012 at 14:59
  • $manufacturer With the second script I'm taking all the "manufacturers" from Magento and what I have is a long list, but I need to divide them in columns of 5. P.s: I updated the original post with the results of print_r(); Commented Dec 17, 2012 at 15:08

1 Answer 1

1

You mix your variables. Probably you want something like this:

<?php
$rows = array_chunk($manufacturers, 5);

foreach ($rows as $row) {
?>
    <ul>
    <?php foreach ($row as $manufacturer) { ?>
        <li>
            <a href="/manufacturer/<?php echo $manufacturer['label']; ?>">
                this is a link
            </a>
        </li>
    <?php } ?>
    </ul>
<?php } ?>

Note how the variables are cascaded in the two foreach loops.

Sign up to request clarification or add additional context in comments.

1 Comment

omg, arkascha thank you sooo much for your time and for your help! Really appreciate that. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.