Jump to content

I have a little problem with a calendar script, and I think I neat some new eyes


postbil.com

Recommended Posts

Hallo Phpfreaks..

I have a little problem with a calendar script, and I think I neat some new eyes.. I have made a calendar where the user can go from one month to another month but the problem is that every month have Wednesday as the first day.. Now I have spend 7 hours to find the error bur without luck.. some one please help me!!

You can se my calendar script at my page www.postbil.com where you also can download the code with a click at “Hent filen her...”

 

Here is my code..

 

<?php

    session_start();

 

?>

<html>

    <head>

        <title></title>

        <link rel="stylesheet" type="text/css" href="style.css">     

        <style type="text/css" media="all">

 

 

table {

    width: 125px;

}

 

td {

    padding: 1px;

    border: 1px solid #666666;

    text-align: center;

}

 

        </style>

    </head>

    <body>

<?php 

 

// Hendt den aktuelle måned og år som integer

    $thismonth = ( int ) date( "m" );

    $thisyear = date( "Y" );

 

// Skift måned

 

    if(isset($_POST['submit']) && $_POST['submit'] == '<-') {

        $thismonth = $_SESSION['thismonth'];

        $thismonth = $thismonth - 1;

        $_SESSION['thismonth'] = $thismonth; 

 

    }

 

    if(isset($_POST['submit']) && $_POST['submit'] == '->') {

        $thismonth = $_SESSION['thismonth'];

        $thismonth = $thismonth + 1;

        $_SESSION['thismonth'] = $thismonth; 

    }   

 

// Find antal dage i den aktuele månede

    $numdaysinmonth = cal_days_in_month( CAL_GREGORIAN, $thismonth, $thisyear );

 

// Opret kalender objekt

    $jd = cal_to_jd( CAL_GREGORIAN, date( "m" ),date( "1" ), date( "Y" ) );

 

// find den første dag i måneden som integer (0 = Søndag, 1 = Mmandag, osv)

    $startday = jddayofweek( $jd , 0 );

 

// find månedens navn

    $monthname = jdmonthname( $jd, 1 );

 

// Find den aktuelle måneds navn

    $monthNames = array();

   

    $monthNames[1] = "Januar";

    $monthNames[2] = "Februar";

    $monthNames[3] = "Marts";

    $monthNames[4] = "April";

    $monthNames[5] = "Maj";

    $monthNames[6] = "Juni";

    $monthNames[7] = "Juli";

    $monthNames[8] = "August";

    $monthNames[9] = "September";

    $monthNames[10] = "Oktober";

    $monthNames[11] = "November";

    $monthNames[12] = "December";

 

 

?>

        <form method="post" action="<?php $_SERVER['PHP_SELF']; ?>">

            <table>

                <tr>

                    <td colspan="7"><div align="center" style="font-size: 20;"><?php echo $monthNames[$thismonth] . ' - ' . $thisyear; ?></div></td>

                </tr>

                <tr>

                    <td>M</td>

                    <td>T</td>

                    <td>W</td>

                    <td>T</td>

                    <td>F</td>

                    <td>S</td>

                    <td>S</td>

                </tr>

                <tr>

 

    <?php

 

        // udfyld tomme celler

        $emptycells = 0;

 

        for( $counter = 0; $counter <  $startday; $counter ++ ) {

            echo "\t\t<td>-</td>\n";

            $emptycells ++;

        }

 

    // udfyld dage

        $rowcounter = $emptycells;

        $numinrow = 7;

        for( $counter = 1; $counter <= $numdaysinmonth; $counter ++ ) {

            $rowcounter ++;

            echo "\t\t<td>$counter</td>\n";

            if( $rowcounter % $numinrow == 0 ) {

                echo "\t</tr>\n";

                if( $counter < $numdaysinmonth ) {

                    echo "\t<tr>\n";

                }

                $rowcounter = 0;

            }

        }

       

    // Reset variabler

 

      $numcellsleft = $numinrow - $rowcounter;

 

       

 

      if( $numcellsleft != $numinrow ) {

 

        for( $counter = 0; $counter < $numcellsleft; $counter ++ ) {

 

            echo "\t\t<td>-</td>\n";

            $emptycells ++;

 

        }

 

       

 

      }

      echo $thismonth;

    ?>

                </tr>

                <tr>

                    <td><input type="submit" name="submit" value="<-" /></td>

                    <td></td>

                    <td></td>

                    <td></td>

                    <td></td>

                    <td></td>

                    <td><input type="submit" name="submit" value="->" /></td>

            </table>

        </form>

    <a href="kalender.zip">Hent filen her...</a>

    </body>

</html>

 

Thanks for your help..

Postbil.com       

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.