Split table into 4 columns with PHP

-1

I have the code below that prints from 28 to 31 lines (according to the month) and I wanted to instead of printing 1 below the other to make 4 columns of 8 or so the layout gets better.

My code

<table border="0">

    <?php
    $total_dias = date("t", mktime(0,0,0,date('m'),'01',date('Y')));

    for($dia = 1; $dia<= $total_dias; $dia++){

        if($dia <= 9){
            $dia = '0'.$dia;
        }

        echo '<tr>';
        echo '<td>'.$dia.'/'.date('m').' - '.$this->agendamento->HorariosDisponiveisPorData($profissional->id, date('Y').'-'.date('m').'-'.$dia).'</td>';
        echo '</tr>';

    }
    ?>
    </table>

How could you break these 31 outputs into 4 columns?

    
asked by anonymous 25.07.2016 / 08:33

1 answer

1
 <?php
    $total_dias = date("t", mktime(0,0,0,date('m'),'01',date('Y')));
    $l = 4; // quantidade de colunas
    $c = 1; // contador auxiliar
    for($dia = 1; $dia<= $total_dias; $dia++){

        if($dia <= 9){
            $dia = '0'.$dia;
        }
        if ($c == 1) {
            echo '<tr>';
        }
        echo '<td>'.$dia.'/'.date('m').' - '.$this->agendamento->HorariosDisponiveisPorData($profissional->id, date('Y').'-'.date('m').'-'.$dia).'</td>';

        // verifica se chegou ao limite de colunas ou se está no último loop.            if ($c == 4 || ($dia + 1) > $total_dias) {
            echo '</tr>';
            $c = 1;
        } else {
            $c++;
        }

    }
    ?>
    
25.07.2016 / 10:28