Check start and end date and insert text between them!

0

Good morning, I have a "ready" code where the user must register an event that will later be shown in a calendar, well the first part is ready and the second is giving me problems, I would like to do a check of the start date and end date and enter a text (Ex: event !!) on days between these dates, PS: dates are acquired via database, all data is already saved

For example: start date 6/6/16 end date 16/6/16, text should appear every day from 6 to 16

        <?php
        include 'connect.php';
        $sql = "select Data_inicio, Data_fim from walldata";
        $result = mysqli_query($con, $sql);
        if ($result->num_rows > 0) {
            while ($row = mysqli_fetch_assoc($result)) {
                $Data_in = $row['Data_inicio'];
                $Data_fim = $row['Data_fim'];
            }
        }
        if (isset($_POST['datac'])) {
            $datee = explode('-', $_POST['datac']);
            $mes = $datee[1];
            $ano = $datee[0];
            $ultimo_dia = date("t", mktime(0, 0, 0, $mes, '01', $ano));
        } else {
            $mes = date('m');
            $ano = date('o');
        }
        if ($mes == date('m')) {
            $ultimo_dia = date("t", mktime(0, 0, 0, $mes, '01', $ano));
            $dias = $ultimo_dia;
        } elseif ($mes == '') {
            $mes = date('m');
            $ano = date('o');
            $dias = $ultimo_dia;
        } else {
            $dias = $ultimo_dia;
        }
        
        ?>
         

        <form method="post" action="date.php">
            <input type="month" name="datac" value="<?php echo $ano ?>-<?php echo $mes ?>" required><input type="submit">
            <table class="table table-striped" width="210" border="2" cellspacing="4" cellpadding="4">
                <tr>
                    <td width="80px"><center>Domingo</center></td>
                <td width="80px"><center>Segunda</center></td>
                <td width="80px" class="center">Terça</td>
                <td width="80px" class="center">Quarta</td>
                <td width="80px" class="center">Quinta</td>
                <td width="80px" class="center">Sexta</td>
                <td width="80px" class="center">Sábado</td>
                </tr>
                <?php
                echo "<tr>";
                for ($i = 1; $i <= $dias; $i++) {
                    $diadasemana = date("w", mktime(0, 0, 0, $mes, $i, $ano));
                    $cont = 0;
                    if ($i == 1) {
                        while ($cont < $diadasemana) {
                            echo "<td></td>";
                            $cont++;
                        }
                    }
                    echo "<td width='100px' height='100px'><center>";
                    echo $i;
                    echo "</center></td>";
                    if ($diadasemana == 6) {
                        echo "</tr>";
                        echo "<tr>";
                    }
                }
                echo "</tr>";
                ?>
            </table>


        </form>
    </body>
</html>

If you have any idea how I can do this; D

    
asked by anonymous 16.06.2016 / 14:53

1 answer

1

There is link , where it does this automatically.

The code below will help you.

Make a range of dates using your start date and end date:

function dateRange($first, $last, $format = 'Y-m-d', $step = '+1 day'){
$dates = array();
$current = strtotime($first);
$last = strtotime($last);

while ($current <= $last) {
    $dates[] = date($format, $current);
    $current = strtotime($step, $current);
}
return $dates;

}

Scroll through the dates by adding the event on days: $eventos[] = array('dataIni' => '2016-01-01', 'dataFim' => '2016-01-10', 'evento' => 'Evento Janeiro'); $eventos[] = array('dataIni' => '2016-01-09', 'dataFim' => '2016-02-5', 'evento' => 'Evento Fevereiro');

$ calendar = array (); foreach ($ events as $ event) {     $ range = dateRange ($ event ['dataIni'], $ event ['dataFim']);     foreach ($ range as $ data) {         $ calendar [$ data] [] = array ('event' = > $ event ['event']);     } }

Scroll through the calendar by checking the days and adding the event description in the places.

    
16.06.2016 / 16:30