By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

PHP calendar in php


Well-Known Coder
I want to create a calendar in php but it's not working out so well I want to be able to make my < and > buttons work and change the date on top of the calendar with one month. but I I can't get it to work. right now the date on top of the calendar is 08-06-2022 and I don't know why this is the case can someone help me
pic of the calendar

<!-- maandag misschien hierover vragen stellen -->
        include "config.php";
    <!DOCTYPE html>
    <html lang="en">
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="stylesheet" href="calender.css">
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
        <table border='0' >
            // Get the current date
            // //dit hieronder is dus een array maar volgens mij kan het ook anders
            // $date = getdate();

            //$date = date("d-m-Y");
            $date = new DateTime();

            //function for the buttons
            if (isset($_POST['currentMonth'])) {
                // kan zijn dat dit er nog in zou moeten $_POST['currentMonth']
                $date = new DateTime();
            if (isset($_POST['monthBack'])) {
                $date = $date->add(new DateInterval('-1 month'));
            else if (isset($_POST['monthFuture'])) {
                //add 1 month??
                $date = $date->add(new DateInterval('P1W2D'));
            //date for above calender
            $calendarTiming = $date->format('d-m-Y');

            // functie voor de maand
            $currentMonth = $date->format('m');

            //check welk jaar het is
            $year = $date->format('Y');

            // hoeveel dagen zitten er in de maand
            $dagenCheck = cal_days_in_month(CAL_GREGORIAN, $currentMonth, $year);

            echo "<br>";

            echo "<thead>";
            echo "<tr>";
            echo "<th colspan='7'>
                <form method='POST' action=''>
                <input type='hidden' name='currentMonth' value='$currentMonth'>
                    <button type='submit' name='monthBack'>
                        <i class='fa fa-angle-left' style='font-size: 20px;'></i>
                         echo " ".
                    "<button type='submit' name='monthFuture'>
                        <i class='fa fa-angle-right' style='font-size: 20px;'></i>
            echo "</tr>";
            echo "<br>";

            echo '<td style="background-color:#d9d9d9">Ma</td>';
            echo '<td style="background-color:#d9d9d9">Di</td>';
            echo '<td style="background-color:#d9d9d9">Wo</td>';
            echo '<td style="background-color:#d9d9d9">Do</td>';
            echo '<td style="background-color:#d9d9d9">Vr</td>';
            echo '<td style="background-color:#d9d9d9">Za</td>';
            echo '<td style="background-color:#d9d9d9">Zo</td>';

            echo "</thead>";
            echo "<tbody>";
                $id = 1;
                $sql = "SELECT * FROM reserveringen WHERE ID=?";
                $stmt = $conn->prepare($sql);
                $stmt->bind_param("i", $id);
                $result = $stmt->get_result();
                while ($row = $result->fetch_assoc()) {
                    $dbStartDatum = $row['start_datum'];
                    $dbEindDatum = $row['eind_datum'];
                    for ($i = 1; $i <= $dagenCheck; $i++){
                        if ($i == 8){
                            echo "<tr><td>" .$i ."</td>";
                        }elseif($i == 15){
                            echo "<tr><td>" .$i ."</td>";
                        }elseif($i == 22){
                            echo "<tr><td>" .$i ."</td>";
                        }elseif($i == 29){
                            echo "<tr><td>" .$i ."</td>";
                        }elseif($i == $dbStartDatum){
                            echo '<td style="background-color: red;">' .$i .'</td>';
                            echo "<td>" .$i ."</td>";
            echo "</tbody>";

New Threads

Latest posts

Buy us a coffee!

Top Bottom