Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Jul 2012
    Location
    Austin, Texas
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help with a PHP calendar script

    I am working on a PHP calendar script that will display a calendar, and my client will have a form so she can add events to the calendar.

    So far the months of the year are showing up and the first row of the calendar is showing up. The year is not. Can anyone look at the code and offer some insights?

    This is the link to what is showing now. http://www.skinsenseminimedspa.com/showcalendar.php

    Below is the full code:

    PHP Code:
    <?php 
    define
    ("ADAY", (60*60*24));
    if ((!isset(
    $_POST['month'])) || (!isset($_POST['year'])))
    {
        
    $nowArray getdate();
        
    $month $nowArray['mon'];
        
    $year $nowArray['year'];
    }
    else 
    {
        
    $month $_POST['month'];
        
    $year $_POST['year'];
    }
    $start mktime (12,0,0,$month,1,$year);
    $firstDayArray getdate($start);

    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title><?php echo "Calendar: " .$firstDayArray['month']." ".$firstDayArray['year']; ?></title>
    <style type="text/css">
        table {
            border:1px solid black;
            border-collapse:collapse;
        }
        th {
            border:1px solid black;
            padding:6px;
            font-weight:bold;
            background:#cccccc;
        }
        td {
        border: 1px solid black;
        padding:6px;
        vertical-align:top;
        width:100px;
        }        
    </style>
    </head>
    <body>
    <h1>Select a Month/Year Combination</h1>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <select name="month">
    <?php 
    $months 
    = Array("January""February""March""April""May""June""July""August""September""October""November""December");
    for (
    $x=1$x <= count($months); $x++)
    {
        echo 
    "<option value=\"$x\"";
        if (
    $x == $month)
        {
            echo 
    " selected";
        }
        echo 
    ">" .$months[$x-1]. "</option>";
    }
    ?>
    </select>
    <select name="year">
    <?php 
    for ($y=2012$y<=2020$y++)
    {
        echo 
    "<option value=\"$y\"";
        if (
    $y == $year)
        {
            echo 
    " selected";
        }
        else 
    ">" .$y"</option>";
    }
    ?>
    </select>

    <button type="submit" name="submit" value="submit">Go!</button><br />

    </form>
    <br />
    <?php 
    $days 
    = Array("Sun""Mon""Tue""Wed""Thu""Fri""Sat");
    echo 
    "<table><tr>\n";
    foreach (
    $days as $day)
    {
        echo 
    "<td>" .$day."</td>\n";
    }
    for (
    $count=0$count < (6*7); $count++)
    {
        
    $dayArray getdate($start);
        if ((
    $count 7) == 0)
        {
            if (
    $dayArray['mon'] != $month)
            {
                break;
            }
            else 
            {
                echo 
    "</tr><tr>\n";
            }
        }
        if (
    count $firstDayArray['wday'] || $dayArray['mon'] !=$month)
        {
            echo 
    "<td>".$dayArray['mday']."</td>\n";
            
    $start += ADAY;
        }
    }
    echo 
    "</tr></table>";
    ?>
    </body>
    </html>

  • #2
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,536
    Thanks
    45
    Thanked 259 Times in 256 Posts
    You mean the years in the dropdown?

  • #3
    New to the CF scene
    Join Date
    Jul 2012
    Location
    Austin, Texas
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yes and the go button is supposed to show up. Below that is a full month long calendar.

  • #4
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    its working ok in firefox

  • #5
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    ah you mean the bit you posted,

    got it working sort of


    here:

    PHP Code:
    <?php 
    define
    ("ADAY", (60*60*24));
    if ((!isset(
    $_POST['month'])) || (!isset($_POST['year'])))
    {
        
    $nowArray getdate();
        
    $month $nowArray['mon'];
        
    $year $nowArray['year'];
    }
    else 
    {
        
    $month $_POST['month'];
        
    $year $_POST['year'];
    }
    $start mktime (12,0,0,$month,1,$year);
    $firstDayArray getdate($start);
    print_r($firstDayArray);

    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title><?php echo "Calendar: " .$firstDayArray['month']." ".$firstDayArray['year']; ?></title>
    <style type="text/css">
        table {
            border:1px solid black;
            border-collapse:collapse;
        }
        th {
            border:1px solid black;
            padding:6px;
            font-weight:bold;
            background:#cccccc;
        }
        td {
        border: 1px solid black;
        padding:6px;
        vertical-align:top;
        width:100px;
        }        
    </style>
    </head>
    <body>
    <h1>Select a Month/Year Combination</h1>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <select name="month">
    <?php 
    $months 
    = Array("January""February""March""April""May""June""July""August""September""October""November""December");
    for (
    $x=1$x <= count($months); $x++)
    {
        echo 
    "<option value=\"$x\"";
        if (
    $x == $month)
        {
            echo 
    " selected";
        }
        echo 
    ">" .$months[$x-1]. "</option>";
    }
    ?>
    </select>
    <select name="year">
    <?php 
    for ($y=2012$y<=2020$y++)
    {
        echo 
    "<option value=\"$y\"";
        if (
    $y == $year)
        {
            echo 
    " selected";
        }
        echo 
    ">" .$y"</option>";
    }
    ?>
    </select>

    <button type="submit" name="submit" value="submit">Go!</button><br />

    </form>
    <br />
    <?php 
    $days 
    = Array("Sun""Mon""Tue""Wed""Thu""Fri""Sat");
    echo 
    "
    <table><tr>"
    ;
    foreach (
    $days as $day){
        echo 
    "
        <td>" 
    .$day."</td>";
    }
    if (
    $firstDayArray['wday'] == 0){$CDays 35;}else{$CDays 42;}
    for (
    $count=0$count $CDays$count++){
        
    $dayArray getdate($start);
        if (
    $dayArray['mon'] == $month){
            if ((
    $count 7) == 0){echo "
            </tr><tr>"
    ;}
            if (
    $count $firstDayArray['wday']) {
                echo 
    "
                <td></td>"
    ;
            }else{
                echo 
    "
                <td>"
    .$dayArray['mday']."</td>";
                
    $start += ADAY;
            }
        }
    }
    echo 
    "
    </tr></table>"
    ;
    ?>
    </body>
    </html>

  • #6
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    Fixed it,

    re-wrote the way it looks for the month

    PHP Code:
    <?php 
    define
    ("ADAY", (60*60*24));
    if ((!isset(
    $_POST['month'])) || (!isset($_POST['year'])))
    {
        
    $nowArray getdate();
        
    $month $nowArray['mon'];
        
    $year $nowArray['year'];
    }
    else 
    {
        
    $month $_POST['month'];
        
    $year $_POST['year'];
    }
    $start mktime (12,0,0,$month,1,$year);
    $firstDayArray getdate($start);
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title><?php echo "Calendar: " .$firstDayArray['month']." ".$firstDayArray['year']; ?></title>
    <style type="text/css">
        table {
            border:1px solid black;
            border-collapse:collapse;
        }
        th {
            border:1px solid black;
            padding:6px;
            font-weight:bold;
            background:#cccccc;
        }
        td {
        border: 1px solid black;
        padding:6px;
        vertical-align:top;
        width:100px;
        }        
    </style>
    </head>
    <body>
    <h1>Select a Month/Year Combination</h1>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <select name="month">
    <?php 
    $months 
    = Array("January""February""March""April""May""June""July""August""September""October""November""December");
    for (
    $x=1$x <= count($months); $x++){
        echo 
    "<option value=\"$x\"";
        if (
    $x == $month){
            echo 
    " selected";
        }
        echo 
    ">" .$months[$x-1]. "</option>";
    }
    ?>
    </select>
    <select name="year">
    <?php 
    for ($y=2012$y<=2020$y++){
        echo 
    "<option value=\"$y\"";
        if (
    $y == $year){
            echo 
    " selected";
        }
        echo 
    ">" .$y"</option>";
    }
    ?>
    </select>

    <button type="submit" name="submit" value="submit">Go!</button><br />

    </form>
    <br />
    <?php 
    $days 
    = Array("Sun""Mon""Tue""Wed""Thu""Fri""Sat");
    echo 
    "
    <table><tr>"
    ;
    foreach (
    $days as $day){
        echo 
    "
        <td>" 
    .$day."</td>";
    }

    for (
    $count=0$count 42$count++){
        
    $dayArray getdate($start);
        if (
    $dayArray['mon'] == $month){
            if ((
    $count 7) == 0){echo "
            </tr><tr>"
    ;}
            if (
    $count $firstDayArray['wday']) {
                echo 
    "
                <td></td>"
    ;
            }else{
                echo 
    "
                <td>"
    .$dayArray['mday']."</td>";
                
    $start += ADAY;
            }
        }else{
            if ((
    $count 7) == 0){
                exit;
            }
            else{
                echo 
    "
                <td></td>"
    ;
            }
        }
    }
    echo 
    "
    </tr></table>"
    ;
    ?>
    </body>
    </html>

  • #7
    Senior Coder
    Join Date
    Sep 2010
    Posts
    2,020
    Thanks
    15
    Thanked 239 Times in 239 Posts
    It's starting to look really nice. I think you're going to have a winner.

  • #8
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    It looks good. How are you getting along with the form to enter the events? I presume that you'll store the data in an SQL database and have the calendar interrogate it.

    I hope you'll feel willing to share the final code when you've completed it

  • #9
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    i like this calender so much, i going to use it for our company holidays,

    i'll use the raw date as the sql key $dayArray['0'] then add links to a Day View page something like:

    PHP Code:
    <?php 
    define
    ("ADAY", (60*60*24));
    if ((!isset(
    $_POST['month'])) || (!isset($_POST['year'])))
    {
        
    $nowArray getdate();
        
    $month $nowArray['mon'];
        
    $year $nowArray['year'];
    }
    else 
    {
        
    $month $_POST['month'];
        
    $year $_POST['year'];
    }
    $start mktime (12,0,0,$month,1,$year);
    $firstDayArray getdate($start);
    print_r($firstDayArray);
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title><?php echo "Calendar: " .$firstDayArray['month']." ".$firstDayArray['year']; ?></title>
    <style type="text/css">
        table {
            border:1px solid black;
            border-collapse:collapse;
        }
        th {
            border:1px solid black;
            padding:6px;
            font-weight:bold;
            background:#cccccc;
        }
        td {
        border: 1px solid black;
        padding:6px;
        vertical-align:top;
        width:100px;
        }        
    </style>
    </head>
    <body>
    <h1>Select a Month/Year Combination</h1>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <select name="month">
    <?php 
    $months 
    = Array("January""February""March""April""May""June""July""August""September""October""November""December");
    for (
    $x=1$x <= count($months); $x++){
        echo 
    "<option value=\"$x\"";
        if (
    $x == $month){
            echo 
    " selected";
        }
        echo 
    ">" .$months[$x-1]. "</option>";
    }
    ?>
    </select>
    <select name="year">
    <?php 
    for ($y=2012$y<=2020$y++){
        echo 
    "<option value=\"$y\"";
        if (
    $y == $year){
            echo 
    " selected";
        }
        echo 
    ">" .$y"</option>";
    }
    ?>
    </select>

    <button type="submit" name="submit" value="submit">Go!</button><br />

    </form>
    <br />
    <?php 
    $days 
    = Array("Sun""Mon""Tue""Wed""Thu""Fri""Sat");
    echo 
    "
    <table><tr><th colspan=\"7\">"
    .$firstDayArray['month']." - ".$firstDayArray['year']."</th></tr>";
    foreach (
    $days as $day){
        echo 
    "
        <th>" 
    .$day."</th>";
    }

    for (
    $count=0$count 42$count++){
        
    $dayArray getdate($start);
        if (
    $dayArray['mon'] == $month){
            if ((
    $count 7) == 0){echo "
            </tr><tr>"
    ;}
            if (
    $count $firstDayArray['wday']) {
                echo 
    "
                <td bgcolor=\"#999999\"></td>"
    ;
            }else{
                echo 
    "
                <td><a href=\"calender.php?date="
    .$dayArray['0']."\">".$dayArray['mday']."</a></td>";
                
    $start += ADAY;
            }
        }else{
            if ((
    $count 7) == 0){
                exit;
            }
            else{
                echo 
    "
                <td bgcolor=\"#999999\"></td>"
    ;
            }
        }
    }
    echo 
    "
    </tr></table>"
    ;
    ?>
    </body>
    </html>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •