2010-04-20 5 views
0

캘린더를 만듭니다.캘린더에 날짜를 삽입하고 함수를 계산합니다.

나는이
< < < < < 년과 같은 연도와 날짜를 기입 >>>>>>
< < < < <개월 >>>>>> 화살표 마크를 클릭하여

년과 달 증가 및 감소.

이제 선택한 연도와 월의 날짜를 입력해야합니다.

나는 달의 첫날과 달의 마지막 날을 계산합니다.

날짜는 첫날부터 채우기 시작해야합니다.

첫 번째 날이 목요일 인 경우 날짜 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); 
    } 

이 내가 함수 phpcal에서 계산 된 날부터 시작 날짜를 삽입 할 수 있습니다 어떻게 내보기 페이지

<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> 

입니까?

답변

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>&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; 
관련 문제