Table, TR each 2 loop, PHP, HTML

前端 未结 2 1819
挽巷
挽巷 2021-01-15 13:27

I got an html table, and I use some loop to get some data, this data is displaying this way:

Data
... next loop
         


        
2条回答
  •  攒了一身酷
    2021-01-15 13:36

    Using the modulo (%) operator is always a great solution for the problem you have above. Since you didn't provide details about the implementation language, I've taken the liberty to provide you with a php example of how it's done.

     tag after 3 outputs of the  tags
        $data       = "Data";       // Placeholder of the data
    
        echo "";
    
        for($i = 1; $i <= 10; $i++)
        {
            echo "{$data}";
    
            if ($i % 3 == 0)
                echo "";       // Close and reopen the  tag
        }
    
        echo "";
    ?>
    

提交回复
热议问题