我正在创建日历。
我这样填写年份和日期
<<<<<年份>>>>>>
<<<<<月>>>>>>
点击箭头标记年份和月份的增加和减少。
现在我必须填写所选年份和月份的日期。
我计算了月份的第一天和月份的最后一天。
日期必须从第一天开始填写。
如果第一天是星期四,那么日期1必须是星期四,接下来的日子必须遵循到最后一天。
这些是我在控制器中的功能
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);
}
这是我的观看页面
<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>
如何插入从函数phpcal中计算的日期开始的日期?
答案 0 :(得分:1)
这是我自己编写的日历脚本。它可以检查一天中的数据库数据并创建链接。看一看,也许它很有帮助:
// 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><<</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>>></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'> </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'> </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;