Parse error: syntax error, unexpected 'echo' (T_ECHO) in foreach



  • I need to make 5 after I've been created. licreated the following ulAnd now, ul continued to be established li♪ Only ul must be all at the same level. Here's the code, CMS OpenCart.

    <?php foreach (array_chunk($category['children'], ceil(count($category['children']) / $category['column'])) as $children) { ?> 
        <div class="children clearfix"> 
            <ul class="children-list children-list-col clearfix"> 
                <?php $k=0; foreach ($children as $child) {(($k%5==0) ?  "</ul><ul>" :"");?> 
                    <li> 
                        <a class="link" href="<?php echo $child['href']; ?>" > 
                            <img class="thumb" src="<?php echo $child['thumb']?>" width="40" height="40" alt="" />
                            <span class="text"><?php echo $child['name']; ?></span></a> 
                    </li> 
                <?php } ?>                          
            </ul> 
        </div>
    <?php } ?>
    

    There may be another solution, thank you in advance.

    UPD: With that code, it makes a mistake that's in the headline.

    <?php foreach ($children as $child) {(($k%5==0) ? echo "</ul><ul>" : echo"");?> 
    

    UPD: On some grounds, code <?php $k=0; foreach ($children as $child) { if($k%5==0) { echo "</ul><ul>"; } $k++;?>which shows signs of efficiency, thank you. tCodeIt doesn't work exactly as I need to... It's been two days since I've been tortured, and it's not about knowledge. ♪

    <div class="children clearfix"> 
                            <ul class="children-list children-list-col clearfix"> 
                                </ul><ul> 
                                <li> 
                                    <a class="link" href="http://rumishop2/component/cmp23" > 
                                    <img class="thumb" src="http://rumishop2/image/cache/no_image-100x100.png" width="40" height="40" alt="" />
                                    <span class="text">Components</span></a> 
                                </li> 
    
                            &lt;li&gt; 
                                &lt;a class="link" href="http://rumishop2/component/PC123" &gt; 
                                &lt;img class="thumb" src="http://rumishop2/image/cache/no_image-100x100.png" width="40" height="40" alt="" /&gt;
                                &lt;span class="text"&gt;PC&lt;/span&gt;&lt;/a&gt; 
                            &lt;/li&gt; 
    
                            &lt;li&gt; 
                                &lt;a class="link" href="http://rumishop2/component/mouse" &gt; 
                                &lt;img class="thumb" src="http://rumishop2/image/cache/no_image-100x100.png" width="40" height="40" alt="" /&gt;
                                &lt;span class="text"&gt;Mice and Trackballs&lt;/span&gt;&lt;/a&gt; 
                            &lt;/li&gt; 
    
                            &lt;li&gt; 
                                &lt;a class="link" href="http://rumishop2/component/monitor" &gt; 
                                &lt;img class="thumb" src="http://rumishop2/image/cache/no_image-100x100.png" width="40" height="40" alt="" /&gt;
                                &lt;span class="text"&gt;Monitors&lt;/span&gt;&lt;/a&gt; 
                            &lt;/li&gt; 
    
                            &lt;li&gt; 
                                &lt;a class="link" href="http://rumishop2/component/printer" &gt; 
                                &lt;img class="thumb" src="http://rumishop2/image/cache/no_image-100x100.png" width="40" height="40" alt="" /&gt;
                                &lt;span class="text"&gt;Printers&lt;/span&gt;&lt;/a&gt; 
                            &lt;/li&gt; 
                            &lt;/ul&gt;&lt;ul&gt; 
                            &lt;li&gt; 
                                &lt;a class="link" href="http://rumishop2/component/scanner" &gt; 
                                &lt;img class="thumb" src="http://rumishop2/image/cache/no_image-100x100.png" width="40" height="40" alt="" /&gt;
                                &lt;span class="text"&gt;Scanners&lt;/span&gt;&lt;/a&gt; 
                            &lt;/li&gt; 
    
                            &lt;li&gt; 
                                &lt;a class="link" href="http://rumishop2/component/web-camera" &gt; 
                                &lt;img class="thumb" src="http://rumishop2/image/cache/no_image-100x100.png" width="40" height="40" alt="" /&gt;
                                &lt;span class="text"&gt;Web Cameras&lt;/span&gt;&lt;/a&gt; 
                            &lt;/li&gt; 
    
                        &lt;/ul&gt; 
                    &lt;/div&gt;
    

    It's the source of the Ctrl+U code, you bet... As you can see here... That the code creates a yol every five, but first of all, it's not 1 level with <ul class="children-list children-list-col clearfix">and inside it... And in addition to everything, is there any reason to be created in the main yol.
    Please help me and pardon me. ♪



  • Replace:

    <?php $k=0; foreach ($children as $child) {(($k%5==0) ?  "</ul><ul>" :"");?>
    

    On:

    <?php $k=0; foreach ($children as $child) { if($k%5==0) { echo "</ul><ul>"; } $k++;?> 
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2