SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    canada
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Column display or dashboard display help

    Hello,

    I have a small script or a dashboard that im working on that displays the col title and a count below the title.
    example:
    Col1 Col2 col3 col4 col5
    3 5 3 8 2
    Col6 Col7 col8 col9 col10
    3 5 3 8 2

    As of now the script displays one below the next.
    What I like to do is:
    display the first 5 cols cross the screen. if the col number reaches 5 repeat the same if there are more records to display below existing display.

    PHP Code:
    $col 0;
    echo 
    '<table border="1">';
    foreach(
    $displayDevice as $key1=> $value)
    {    if (
    $value 0)
        {    if(
    $col 4)
            {    
    $col++;
                echo 
    "<tr><td>" $key1  "</td></tr>"
                echo 
    "<tr><td>" $value "</td></tr>";
            } else { 
    $col 0;}
        }
    }
    echo 
    "</table>"
    Any thoughts on this?

    Thanks

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,398
    Mentioned
    147 Post(s)
    Tagged
    4 Thread(s)
    PHP Code:
    $col 0;
    $titlerow = array();
    $valuerow = array();
    echo 
    '<table border="1">';
    foreach (
    $displayDevice as $key1=> $value) {    
      if (
    $value 0) {   // add new values to the two rows  
        
    $col++;
        
    $titlerow[] = $key1
        
    $valuerow[] = $value;
        if (
    $col 4) {    // when there are five columns then display the two rows
          
    echo "<tr><td>" implode("</td><td>",  $titlerow) . "</td></tr>"
          echo 
    "<tr><td>" implode("</td><td>",  $valuerow) . "</td></tr>"
          
    // reset variables
          
    $col 0;
          
    $titlerow '';
          
    $valuerow '';
        }
      }
    }
    if (
    $col 0) {   // display the remaining values (if any)
      
    echo "<tr><td>" implode("</td><td>",  $titlerow) . "</td></tr>"
      echo 
    "<tr><td>" implode("</td><td>",  $valuerow) . "</td></tr>"
    }
    echo 
    "</table>"
    edit: actually, if you can have a number of values that isn't a multiple of 5 (12 for example), then you'd want to add three empty td's to the last rows.
    Last edited by guido2004; Jan 17, 2013 at 15:09. Reason: added an afterthought

  3. #3
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    canada
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Guido2004.. it works ...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •