Print Specified Number of Columns in a Page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mfaisalwarraich
    New Member
    • Oct 2007
    • 194

    Print Specified Number of Columns in a Page

    Hi All,

    I want to print the data in specified number of columns on a web page. for example i wana show only 7 columns on a page and i also want empty column between that column to seperate each other. how i can achieve this using PHP?

    Anybody would help me i will be grateful to him/her.

    thank you.

    regards

    Faisal
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    What do you mean by an empty column between the columns?

    You can use the modulus operator (%) to add a row after a set number of columns. Like:
    [code=php]
    echo "<table><tr >";
    for($i = 0; $i < 100; $i++)
    {
    // Add a row every 7 columns
    if($i % 7 == 0 && $i != 0) {
    echo "</tr><tr>";
    }

    // Print the column
    echo "<td>$i</td>";
    }
    echo "</tr></table>";
    [/code]

    Comment

    Working...