Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7703465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:27:54+00:00 2026-05-31T23:27:54+00:00

So I am making a calender form for a client to choose a course

  • 0

So I am making a calender form for a client to choose a course to book… this then uploads to a link table between the course and the customer but I cant for the life of me get the calender into a calender like grid properly… my code is simple and sweet but i need to do this non object orientated (i have small java experience but nothing else)….

I have ben staring at this all day but to no avail!

(I am learning so im not going down the routes of protecting it etc… this is for self learning so just needs to work and help me understand where I am going wrong)

The code:

<?
if(@$_POST['month'])
{    
$_SESSION['month'] = trim($_POST['month']);
}

elseif(!isset($_SESSION['month']))
{    
$_SESSION['month'] = '3';
}

if(@$_POST['year'])
{    
$_SESSION['year'] = trim($_POST['year']);
}

elseif(!isset($_SESSION['year']))
{    
$_SESSION['year'] = '2012';
}

?>

<form name="sort" action="calender.php" method="post">
<select name="month">
    <option value="1">January</option>
    <option value="2">February</option>
    <option value="3">March</option>
    <option value="4">April</option>
    <option value="5">May</option>
    <option value="6">June</option>
    <option value="7">July</option>
    <option value="8">August</option>
    <option value="9">September</option>
    <option value="10">October</option>    
    <option value="11">November</option>
    <option value="12">December</option>
</select>
<select name="year">
    <option value="2012">2012</option>
    <option value="2013">2013</option>
    <option value="2014">2014</option>
    <option value="2015">2015</option>
    <option value="2016">2016</option>
    <option value="2017">2017</option>
    <option value="2018">2018</option>
    <option value="2019">2019</option>
    <option value="2020">2020</option>
    <option value="2021">2021</option>
    <option value="2022">2022</option>
    <option value="2023">2023</option>
</select>
<input type="submit" value=" - !Go! - " />
</form><br />
<?php



$month = $_SESSION['month'];
$year = $_SESSION['year'];
$day = 1;

$nummonth = cal_days_in_month(CAL_GREGORIAN, $month, $year);

echo "<form name='choosedate' action='datechosen' method='get'>";

for($day = 1; $day <= $nummonth; $day++)
{

echo $day."/".$month."/".$year."<input type='radio' name='coursedate value='".$day."-".$month."-".$year."' /><br />";

}

echo "<input type='submit' value=' - Submit - ' /></form>";

?>

Thank you for any help you can give… any advice or even just a point in the right direction is much much much appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T23:27:55+00:00Added an answer on May 31, 2026 at 11:27 pm

    Here’s a function I threw together that should work with your current code. To use the function, simply call it by this:

    # $month, $year must be numeric.  ie. Aug = 8
    # The 3rd parameter is optional.  It will display the calendar month starting 
    # on either Monday or Sunday, depending on your preference.  Default is 'sun',
    # but anything other than 'sun' will cause the displayed week to start on Monday.
    
    printCalendarMonth($month, $year, 'mon'); 
    

    Then you need to include the code below. I’ve commented in it to help.

    function printCalendarMonth($month, $year, $firstDay = 'sun')
    {
        # Get the number of days in the month
        $totalDays = cal_days_in_month(CAL_GREGORIAN, $month, $year);
        # Get the day-of-the-week the 1st starts on
        $date = getDayOfTheWeek($month,$year, $firstDay);
        # print out the table headers
        printTableHeader($date, $firstDay);
        # print table body
        printTableBody($totalDays, $date['startDay']);
        # print out the table headers
        printTableFooter();
    
    }
    
    function printTableHeader($date, $firstDay)
    {
        # The standard "Sunday First" calendar of days
        $days = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'); 
        # change to the "Monday First" calendar
        if($firstDay == 'mon'){
            # the days of the week
            $days = array('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'); 
        }
        # print the header HTML for the calendar table
        echo '<h1>' . $date['month'] . ', ' . $date['year'] . '</h1>' . "\n";
        echo '<table>' . "\n";
        echo "\t" . '<thead>' . "\n";
        echo "\t\t" . '<tr>' . "\n";
        # loop through the days and print them out
        foreach($days as $day){
            echo "\t\t\t" . '<th>' . $day . '</th>' . "\n"; 
        }
        # close table header HTML
        echo "\t\t" . '</tr>' . "\n";
        echo "\t" . '</thead>' . "\n";
        echo "\t" . '<tbody>' . "\n";
    }
    
    function printTableBody($totalDays, $startDay)
    {
        # value to represent the day the last day of the month falls on
        $endDay = 6;
        # value to represent the current day of the week
        $currDay = 1;
        # Loop through all the days of the month
        for($todayDate=1; $todayDate <= $totalDays; $todayDate++){
            # start a new row every 7 days
            if($currDay % 7 == 1) { echo "\t\t" . '<tr>' . "\n"; }
            # increment the current day (do this before the closing table row)
            $currDay++;
            # loop through the number of starting days to represent the days of the previous month
            $currDay = printPrevMonthDays($startDay, $currDay);
            # print out the table cell for this day.  Start a new row for every 7 days
            echo "\t\t\t" . '<td>'.$todayDate.'</td>' . "\n";
            # close the table row every 7 days
            if($currDay % 7 == 1) { echo "\t\t" . '</tr>' . "\n"; }
        }
    }
    
    function printTableFooter($firstDay)
    {
        echo "\t" . '</tbody>' . "\n";
        echo '</table>' . "\n";
    }
    
    function getDayOfTheWeek($month, $year, $firstDay = 'sun')
    {
        $date = array();
        # save out the date values
        $time = mktime(0, 0, 0, $month, 1, $year);
        $date['dotw'] = strtolower( date("D", $time) );
        $date['month'] = strtolower( date("F", $time) );
        $date['year'] = strtolower( date("Y", $time) );
    
        switch($date['dotw']){
            default:
            case 'sun': $date['startDay'] = 0; break;
            case 'mon': $date['startDay'] = 1; break;
            case 'tue': $date['startDay'] = 2; break;
            case 'wed': $date['startDay'] = 3; break;
            case 'thu': $date['startDay'] = 4; break;
            case 'fri': $date['startDay'] = 5; break;
            case 'sat': $date['startDay'] = 6; break;
        }
        # subtract one if we want to display Monday as the first day of the week
        if($firstDay == 'mon')
            $date['startDay'] = $date['startDay'] - 1;
        # return date array object
        return $date;
    }
    
    # passing startDay by reference
    function printPrevMonthDays(&$startDay, $currDay)
    {
        while($startDay != 0){
            echo "\t\t\t" . '<td>[blank]</td>' . "\n";  
            # increment the current day
            $currDay++;
            # decrement the startDay
            $startDay--;    
        }
        # return zero to 
        return $currDay;
    }
    

    The main concept is as DaveyBoy states, it’s just a X-by-X array. The only real trick is that days don’t always start on the first day of the week, so you need to print out some “blank” days of the previous month.

    You could easily do this by creating a 7-by-X 2D array and just loop through that, but it will be the same concepts where you need to fill in the blank spaces.

    Of course, there’s some hard coded values in there, which can be improved upon but for the sake of this tutorial, here it is.

    Hope it helps!
    Cheers!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Making my first steps in RIA Services (VS2010Beta2) and i encountered this problem: created
I have this simple case statement : class_name = case link_path when current_page?(jobs_path) then
I'm making a small Calendar application with some specific functions for my userbase but
I'm having a trouble making a form work. As I see it, everything is
This project is literally making me lose sleep. I think about it all day
I have attempted this is many ways but failed consistently, hopefully you can help
Im in the making of a little project at school: A client where you
I am making ajax call like this $(document).ready(function() { var abc = new Array();
I'm making a custom event calendar with PHP. I am trying to get the
Making echo of a question around the web: Is the syntax for svn:ignore patterns

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.