#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2009
    Posts
    215
    Rep Power
    6

    Exclamation Add a line break automatically after a specific count for a table's elements


    Hello, I have a code which is automatically adding values using the th tag, and would like to insert a line break automatically after the 4th th is met, and then on the new line continue adding the values. My sample code is as follows:

    PHP Code:
    <table class="map-view"> <thead> <tr> <?php  foreach($rootMenus as $rootMenu) { $item cGetItemMenu($_SESSION['IDLANG'], $rootMenu['IDMENU']); ?> <th> <?php if($item != null) { switch($item[0]['IDITEMTYPE']) { case 5?> <a href="#" onclick="<?php echo $item[0]['CONTENT'];?>"><?php echo $rootMenu['TITLE']; ?></a> <?php break; case 6:$infoModule cGetInfoModClients($item[0]['IDLINK']);  if(!empty($infoModule)) { switch($infoModule[0]['CODE']) { case "PATHCONTROLLER" : echo getURLRewriting($item[0]['IDITEMTYPE'], $_SESSION['IDLANG'], $infoModule[0]['IDCLIENTMODULE'], $infoModule[0]['NAME'], $rootMenu['TITLE']); break; case "JSPOPUP" ?> <a href="#" onclick="<?php echo $infoModule[0]['ACTION'];?>"><?php echo $rootMenu['TITLE']; ?></a> <?php break; } } break; default: echo getURLRewriting($item[0]['IDITEMTYPE'], $_SESSION['IDLANG'], $item[0]['IDITEM'], $item[0]['TITLETRANSLATION'], $rootMenu['TITLE']); break; } } else { echo $rootMenu['TITLE']; } ?> </th>
    Anyone can help me?
    Last edited by lordrt21; December 13th, 2012 at 02:20 AM.
  2. #2
  3. For POny!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Location
    Amsterdam
    Posts
    416
    Rep Power
    115
    Your code could use some indentation. Apart from that you could use the modulus operator ].

    Here an example run it and you see how it works:

    PHP Code:
    <?php

    for($i=1;$i<20;$i++){
        
        if(
    $i != 0){     // modulus   (if the remainder of $i/4 is not 0)
            
    echo 'normal line '.$i.'<br />';   
        }else{
            echo 
    'special line '.$i.'<br />';
            
    // this applies to every fourth line 
        
    }
        
    }


    ?>

    Comments on this post

    • lordrt21 agrees
    Last edited by aeternus; December 13th, 2012 at 03:16 AM.
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2009
    Posts
    215
    Rep Power
    6
    thanks for the heads-up

IMN logo majestic logo threadwatch logo seochat tools logo