Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am new to PHP. I have written a code to increase and decrease month and year on clicking next and previous buttons but it does not work accordingly. Please help. Code is given below. you can run it in your localhost. Just click on next and previous button and observe the issue. If you don't understand, give a comment.

Code:


XML
<html>
<?php
error_reporting(0);
        $date=time();

        $day=date('d',$date); // current day in number.
        $month=date('m',$date); // current month in number.
        $year=date('Y',$date); // current year in number.

        $currentTimeStamp= strtotime("$year-$month-$day");
        $monthName  = date("F", $currentTimeStamp); // Get Current Month Name.
        $numDays = date("t",$currentTimeStamp); // Get how many days are there in the current month.
?>

<?php
        if(isset($_GET['p']))
        {

                $month=$month-1;
                $currentTimeStamp= strtotime("$year-$month-$day");
                $monthName  = date("F", $currentTimeStamp);
        }
        else if (isset($_GET['q']))
        {

                $month=$month+1;
                $currentTimeStamp= strtotime("$year-$month-$day");
                $monthName  = date("F", $currentTimeStamp);
        }
?>

    <table>
        <tr>
            <td>
                    <td>
                    <?php
                        echo "<a href='cal.php?p=$month'> << </a>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                    ?>
                    </td>

                    <th> <?php echo $monthName.", ".$year."  "; ?> </th>


                    <td colspan=5 align="left">
                    <?php
                        echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <a href='cal.php?q=$month'> >> </a>
                        ";
                    ?>
            </td>
        </tr>
    </table>

</html>
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900