Check initial and final date and insert text between them!

Asked

Viewed 376 times

0

Good morning, I have a code "ready" in which the user must register an event that will later be shown in a calendar, well the first part is already ready but the second is giving me problems, I would like to do a check of the initial and final date and insert a text (Ex: event!!) in the days between these dates,PS: the dates are purchased via database, all data are already recorded


example: start date 6/6/16 end date 16/6/16 , the text should appear on all days 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 that ;D Imagem de como está atualmente!

  • I need you to be more specific. Where do you want to put the word ? Type, on each date ?

  • Yes on the days when the event happens

  • example, start date 6/6/16 end date 16/6/16 , the text should appear on all days from 6 to 16

1 answer

1


There is the http://fullcalendar.io/, where does it automatic.

The code below will help you.

Make a range of dates using their initial date and their final 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 the 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');

$Flag = 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 to the locations.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.