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

  • Home
  • SEARCH
  • 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 747665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:13:54+00:00 2026-05-14T14:13:54+00:00

I am creating a calendar. I fill the year and date like this <<<<<

  • 0

I am creating a calendar.

I fill the year and date like this
<<<<< Year >>>>>>
<<<<< month >>>>>>

By clicking on the arrow marks the year and month increase and decrease.

Now I have to fill the dates for the year and month selected.

I calculate the first day of month and last date of the month.

The dates must start filling from the first day.

If the first day is Thursday the date 1 must be on Thursday and the next days must follow that till the last date.

These are my functions in my controller

function phpcal()
    {
        $month=04;
        $day=01;
        $year=2010;
        echo date("D", mktime(0,0,0,$month,$day,$year)); //here i am calculating the first day of the month
        echo '<br>lastdate'.date("t", strtotime($year . "-" . $month . "-01"));'' here i am calculating the lasdt date of the month
        //echo '<br>'.$date_end  = $this->lastOfMonth();
        $this->load->view('phpcal');
    }
function firstOfMonth($m1,$y1) 
{ 
           return date("m/d/Y", strtotime($m1.'/01/'.$y1.' 00:00:00')); 
} 
function lastOfMonth() 
{ 
           return date("m/d/Y", strtotime('-1 second',strtotime('+1                                                                month',strtotime(date('m').'/01/'.date('Y').' 00:00:00')))); 
}
function phpcalview()
    {
        $year = $this->input->post('yearvv');
        $data['year'] = $this->adminmodel->selectyear();
        $data['date'] = $this->adminmodel->selectmonth();
        //print_r($data['date'] );

        $this->load->view('phpcal',$data); 
    }

This is my view page

<table cellpadding="2" cellspacing="0" border="1" bgcolor="#CCFFCC" align="center"  class="table_Style_Border">
<?  if(isset($date))
{
foreach($date as $row)
{?>


<tr>
    <td><?= $row['dbDate1'];?></td> <td><?= $row['dbDate2'];?></td> <td><?= $row['dbDate3'];?></td> <td><?= $row['dbDate4'];?></td>     <td><?= $row['dbDate5'];?></td> <td><?= $row['dbDate6'];?></td> <td><?= $row['dbDate7'];?></td>
</tr>
<tr bgcolor="#FFFFFF">
    <td><?= $row['dbDate8'];?></td> <td><?= $row['dbDate9'];?></td> <td><?= $row['dbDate10'];?></td> <td><?= $row['dbDate11'];?></td> <td><?= $row['dbDate12'];?></td> <td><?= $row['dbDate13'];?></td> <td><?= $row['dbDate14'];?></td>
</tr>
<tr>
    <td><?= $row['dbDate15'];?></td> <td><?= $row['dbDate16'];?></td> <td><?= $row['dbDate17'];?></td> <td><?= $row['dbDate18'];?></td> <td><?= $row['dbDate19'];?></td> <td><?= $row['dbDate20'];?></td> <td><?= $row['dbDate21'];?></td>
</tr>
<tr bgcolor="#FFFFFF">
    <td><?= $row['dbDate22'];?></td> <td><?= $row['dbDate23'];?></td> <td><?= $row['dbDate24'];?></td> <td><?= $row['dbDate25'];?></td> <td><?= $row['dbDate26'];?></td> <td><?= $row['dbDate27'];?></td> <td><?= $row['dbDate28'];?></td>
</tr>
<tr>
    <td><?= $row['dbDate29'];?></td> <td><?= $row['dbDate30'];?></td> <td><?= $row['dbDate31'];?></td> <td><?= $row['dbDate1'];?></td> <td><?= $row['dbDate1'];?></td> <td><?= $row['dbDate1'];?></td> <td><?= $row['dbDate1'];?></td>
</tr>

</tr>
<? }} ?>
</table>

How can I insert the dates starting from the day calculated in the function phpcal?

  • 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-14T14:13:54+00:00Added an answer on May 14, 2026 at 2:13 pm

    This is a calendar script I partly wrote myself. It can check database data against a day and create a link. Take a look, maybe it’s helpful:

    // Start table
    $display .= '<table class="calendar_table" border="0">';
    // set the default timezone to use. Available since PHP 5.1
    date_default_timezone_set('UTC');
    //This gets today's date
    $date = time();
    // Set the value to today
    $today = date('d', $date);
    //This will get the value from the url
    if($_GET['month'] && $_GET['year']){
        $month = $_GET['month'];
        $year = $_GET['year'];
    }else{
        //This puts the day, month, and year in seperate variables
        $day = date('d', $date);
        $month = date('m', $date);
        $year = date('Y', $date);
    }
    // Set values for previous and next month
    $nextMonth = $month+1;
    $previousMonth = $month-1;
    // And for the year
    $nextYear = $year;
    $previousYear = $year;
    
    // Check the month (there are only 12 so, fix)
    if($month == '1'){
        $previousMonth = '12';
        $previousYear = $previousYear-1;
    }elseif($month == '12'){
        $nextMonth = '1';
        $nextYear = $nextYear+1;
    }
    
    //Here we generate the first day of the month
    $first_day = mktime(0,0,0,$month, 1, $year);
    
    //This gets us the month name
    $title = date('F', $first_day); 
    
    //Here we find out what day of the week the first day of the month falls on
    $day_of_week = date('D', $first_day);
    
    //Once we know what day of the week it falls on, we know how many blank days occure before it. If the first day of the week is a Sunday then it would be zero
    switch($day_of_week){
        case "Sun": $blank = 0; break;
        case "Mon": $blank = 1; break;
        case "Tue": $blank = 2; break;
        case "Wed": $blank = 3; break;
        case "Thu": $blank = 4; break;
        case "Fri": $blank = 5; break;
        case "Sat": $blank = 6; break;
    }
    
    //We then determine how many days are in the current month
    $days_in_month = cal_days_in_month(0, $month, $year); 
    
    // Get the url, check for home or module
    if($_GET['pageName'] == 'Home'){
        $link_prefix = '?pageName=Home';
    }else{
        $link_prefix = '?module=Agenda';
    }
    
    //Here we start building the table heads
    $display .= "<tr class='calendar_header'><td class='calendar_navigation'><a href='".$link_prefix.'&month='.$previousMonth."&year=".$previousYear."' class=navigationLink>&lt;&lt;</a></td><td colspan='5' class='calendar_title_frontpage'> $title $year </td><td class='calendar_navigation'><a href='".$link_prefix.'&month='.$nextMonth."&year=".$nextYear."' class=navigationLink>&gt;&gt;</a></td></tr>";
    $display .= "<tr class='calendar_weeks'><td class='calendar_weeks'>Zo</td><td class='calendar_weeks'>Ma</td><td class='calendar_weeks'>Di</td><td class='calendar_weeks'>Wo</td><td class='calendar_weeks'>Do</td><td class='calendar_weeks'>Vr</td><td class='calendar_weeks'>Za</td></tr>";
    
    //This counts the days in the week, up to 7
    $day_count = 1;
    
    $display .= "<tr>";
    //first we take care of those blank days
    while ($blank > 0){
        $display .= "<td class='calendar_days'>&nbsp;</td>";
        $blank = $blank-1;
        $day_count++;
    }
    
    //sets the first day of the month to 1
    $day_num = 1;
    
    // Create query to get all the info from the database
    $BlaatCms->DB->build(array('select' => 'id,dates,title,description','from' => 'calendar')); 
    
    
    // Create array
    $events = array();
    
    // Getting the data from the database and put it in an array
    while($calendar = $BlaatCms->DB->fetch($BlaatCms->DB->execute())){
        if(date('m', $calendar['dates']) == $month){
            $events[intval($BlaatCms->unixstamp_to_mmddyyyy($calendar['dates']))] .= '<a href="?module=Agenda&id='.$calendar['id'].'">'.date('d',$calendar['dates']).'</a>';
        }
    }
    
    
    //count up the days, untill we've done all of them in the month
    while ($day_num <= $days_in_month){
    
        if(array_key_exists($day_num,$events)){
            if($day_num == $today && $month == date('m', $date) && $year == date('Y', $date)){
                $display .= "<td class='calendar_days_event_current'>".$events[$day_num]."</td>";
            }else{
                $display .= "<td class='calendar_days_event'>".$events[$day_num]."</td>";
            }
    
        }else{
            if($day_num == $today && $month == date('m', $date) && $year == date('Y', $date)){
                $display .= "<td class='calendar_days_current'>".$day_num."</td>";
            }else{
                $display .= "<td class='calendar_days'>".$day_num."</td>";
            }
        }
    
        $day_num++;
        $day_count++;
    
        //Make sure we start a new row every week
        if ($day_count > 7){
            $display .= "</tr><tr align=center>";
            $day_count = 1;
        }
    
    } 
    
    //Finaly we finish out the table with some blank details if needed
    while ( $day_count >1 && $day_count <=7 ){
        $display .= "<td class='calendar_days'>&nbsp;</td>";
        $day_count++;
    }
    
    $display .= "</tr>";
    
    // Show link to nieuws archive
    $display .= '<tr><td colspan="7" class="calendar_readmore_frontpage"><a href="?module=Agenda">'.$agenda_config['textOverview'].'</a></td>';
    
    $display .= "</table>";
    // Echo the table
    echo $display;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a calendar in PHP and in the database have a date,
I am creating a calendar based app. I have two dates say present date,
I'm creating a calendar that displays a timetable of events for a month. Each
I am creating a calendar application. I have a Appointment table, and a Person
I'm creating a little calendar app in Django. I have two model classes; Calendar
I have been tasked at re-creating an MS Access calendar in a winforms C#
I've created a category to help me deal with creating dates from year, month,
I am creating a calendar using a HTML table. I have a problem where
i am using drupal events calendar and i am creating events. Now i want
I am creating a calendar table for my warehouse. I will use this as

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.