2012-07-11 18 views
-1

我的網站,我做了與events.it日曆,這個月工作正常。但我很困惑如何在沒有刷新頁面的情況下將上個月和下個月與事件關聯起來。我想用阿賈克斯,但我不知道。任何幫助是受歡迎的。提前致謝。 我的代碼:如何鏈接在日曆上一個和下一個月沒有刷新頁面

<h1><?php echo "<strong>".$current_month_text."</strong>";?></h1> 
<a href="javascript:;" onclick="newCalender(<?php echo $previous_month;?>)">Previous</a> 

<table cellspacing="0"> 
     <thead> 
     <tr> 
      <th>Sun</th> 
      <th>Mon</th> 
      <th>Tue</th> 
      <th>Wed</th> 
      <th>Thu</th> 
      <th>Fri</th> 
      <th>Sat</th> 
     </tr> 
     </thead> 
     <tr> 
      <?php 

      for($i=0; $i< $total_rows; $i++) 
      { 
       for($j=0; $j<7;$j++) 
       { 
        $day++;     

        if($day>0 && $day<=$total_days_of_current_month) 
        { 
         //YYYY-MM-DD date format 
         $date_form = "$current_year/$current_month/$day"; 

         echo '<td'; 

         //check if the date is today 
         if($date_form == $today) 
         { 
          echo ' id="today"'; 
         } 

         //check if any event stored for the date 
         if(array_key_exists($day,$events)) 
         { 
          //adding the date_has_event class to the <td> and close it 
          echo ' class="date_has_event"> '.$day; 

          //adding the eventTitle and eventContent wrapped inside <span> & <li> to <ul> 
          echo '<div class="events"><ul>'; 

          foreach ($events as $key=>$event){ 
           if ($key == $day){ 
           foreach ($event as $single){ 
            echo '<li>';      
            echo anchor("events_detail/$single->url",'<span class="title">'.$single->event_title.'</span><span class="desc">'.character_limiter(strip_tags(stripslashes($single->description)),100).'</span>');      
            echo '</li>'; 
           } // end of for each $event 
           } 

          } // end of foreach $events 


          echo '</ul></div>'; 
         } // end of if(array_key_exists...) 

         else 
         { 
          //if there is not event on that date then just close the <td> tag 
          echo '> '.$day; 
         } 
         echo "</td>"; 
        } 
        else 
        { 
         //showing empty cells in the first and last row 
         echo '<td class="padding">&nbsp;</td>'; 
        } 
       } 
       echo "</tr><tr>"; 
      } 


      ?> 
     </tr> 

    </table> 

回答

0

鑑於壓延頁:

<div class="calender">  
<span class="detail_button_left">&nbsp;</span> 
    <a class="detail_bg" id="prev_button" href="<?php echo base_url() . "calender/". $previous_month;?>" >Previous</a> 
<span class="detail_button_right">&nbsp;</span> 
<div class="calender_next_btn"> 
    <span class="detail_button_left">&nbsp;</span> 
     <a class="detail_bg" id="next_button" href="<?php echo base_url() . "calender/". $next_month; ?>" >Next</a> 
    <span class="detail_button_right">&nbsp;</span> 
</div> 
<h1><?php echo "<strong>".$current_month_text."</strong>";?></h1> 
<div class="layout-grid"> 
    <table cellspacing="0"> 
     <thead> 
      <tr> 
       <th>Sun</th> 
       <th>Mon</th> 
       <th>Tue</th> 
       <th>Wed</th> 
       <th>Thu</th> 
       <th>Fri</th> 
       <th>Sat</th> 
      </tr> 
    </thead> 
      <tr> 
       <?php 
        for($i=0; $i< $total_rows; $i++) 
         { 
          for($j=0; $j<7;$j++) 
           { 
            $day++;     
            if($day>0 && $day<=$total_days_of_current_month) 
            { 
             //YYYY-MM-DD date format 
        $date_form = "$current_year/$current_month/$day"; 
        echo '<td'; 
        //check if the date is today 
        if($date_form == $today) 
        { 
              echo ' id="today"'; 
        } 
        //check if any event stored for the date 
        if(array_key_exists($day,$events)) 
        { 
              //adding the date_has_event class to the <td> and close it 
              echo ' class="date_has_event"> '.$day; 
         //adding the eventTitle and eventContent wrapped inside <span> & <li> to <ul> 
              echo '<div class="events"><ul>'; 
         foreach ($events as $key=>$event) 
              { 
               if ($key == $day) 
               { 
                foreach ($event as $single) 
                { 
                 echo '<li>';      
          echo anchor("events_detail/$single->url", 
                   '<span class="title">'.$single->event_title. 
                   '</span><span class="desc">'.character_limiter(strip_tags(stripslashes($single->description)),100). 
                   '</span>');      
          echo '</li>'; 
                } // end of for each $event 
         } 
              } // end of foreach $events 
              echo '</ul></div>'; 
        } // end of if(array_key_exists...) 
        else 
        { 
              //if there is not event on that date then just close the <td> tag 
              echo '> '.$day; 
        } 
        echo "</td>"; 
            }else{ 
        //showing empty cells in the first and last row 
        echo '<td class="padding">&nbsp;</td>'; 
            } 
       } 
       echo "</tr><tr>"; 
          } 

      ?> 
      </tr> 
    </table> 
</div> 
</div> 

模型頁:

function calender($slug=0) 
    { 
     $timeid = $this->uri->segment(3); 
     if($timeid==0) 
     { 
      $time = time(); 
     }else{ 
      $time = $timeid; 
     } 
     if(!empty($slug)){ 
     $data['events']=$this->user_model->getEvents($slug); 
     $today = date("Y/n/j", time()); 
    $data['today']= $today; 
    $current_month = date("n", $slug); 
    $data['current_month'] = $current_month; 
    $current_year = date("Y", $slug); 
    $data['current_year'] = $current_year; 
    $current_month_text = date("F Y", $slug); 
    $data['current_month_text'] = $current_month_text; 
    $total_days_of_current_month = date("t", $slug); 
    $data['total_days_of_current_month']= $total_days_of_current_month; 
    $first_day_of_month = mktime(0,0,0,$current_month,1,$current_year); 
    $data['first_day_of_month'] = $first_day_of_month; 
    //geting Numeric representation of the day of the week for first day of the month. 0 (for Sunday) through 6 (for Saturday). 
    $first_w_of_month = date("w", $first_day_of_month); 
    $data['first_w_of_month'] = $first_w_of_month; 
    //how many rows will be in the calendar to show the dates 
    $total_rows = ceil(($total_days_of_current_month + $first_w_of_month)/7); 
    $data['total_rows']= $total_rows; 
    //trick to show empty cell in the first row if the month doesn't start from Sunday 
    $day = -$first_w_of_month; 
    $data['day']= $day; 
    $next_month = mktime(0,0,0,$current_month+1,1,$current_year); 
    $data['next_month']= $next_month; 
    $next_month_text = date("F \'y", $next_month); 
    $data['next_month_text']= $next_month_text; 
    $previous_month = mktime(0,0,0,$current_month-1,1,$current_year); 
    $data['previous_month']= $previous_month; 
    $previous_month_text = date("F \'y", $previous_month); 
    $data['previous_month_text']= $previous_month_text; 
    $next_year = mktime(0,0,0,$current_month,1,$current_year+1); 
    $data['next_year']= $next_year; 
    $next_year_text = date("F \'y", $next_year); 
    $data['next_year_text']= $next_year_text; 
    $previous_year = mktime(0,0,0,$current_month,1,$current_year-1); 
    $data['previous_year']=$previous_year; 
    $previous_year_text = date("F \'y", $previous_year); 
    $data['previous_year_text']= $previous_year_text; 
     } 
     else{ 
     $data['events']=$this->user_model->getEvents($time); 
     $today = date("Y/n/j", time()); 
    $data['today']= $today; 
    $current_month = date("n", $time); 
    $data['current_month'] = $current_month; 
    $current_year = date("Y", $time); 
    $data['current_year'] = $current_year; 
    $current_month_text = date("F Y", $time); 
    $data['current_month_text'] = $current_month_text; 
    $total_days_of_current_month = date("t", $time); 
    $data['total_days_of_current_month']= $total_days_of_current_month; 
    $first_day_of_month = mktime(0,0,0,$current_month,1,$current_year); 
    $data['first_day_of_month'] = $first_day_of_month; 
    //geting Numeric representation of the day of the week for first day of the month. 0 (for Sunday) through 6 (for Saturday). 
    $first_w_of_month = date("w", $first_day_of_month); 
    $data['first_w_of_month'] = $first_w_of_month; 
    //how many rows will be in the calendar to show the dates 
    $total_rows = ceil(($total_days_of_current_month + $first_w_of_month)/7); 
    $data['total_rows']= $total_rows; 
    //trick to show empty cell in the first row if the month doesn't start from Sunday 
    $day = -$first_w_of_month; 
    $data['day']= $day; 
    $next_month = mktime(0,0,0,$current_month+1,1,$current_year); 
    $data['next_month']= $next_month; 
    $next_month_text = date("F \'y", $next_month); 
    $data['next_month_text']= $next_month_text; 
    $previous_month = mktime(0,0,0,$current_month-1,1,$current_year); 
    $data['previous_month']= $previous_month; 
    $previous_month_text = date("F \'y", $previous_month); 
    $data['previous_month_text']= $previous_month_text; 
    $next_year = mktime(0,0,0,$current_month,1,$current_year+1); 
    $data['next_year']= $next_year; 
    $next_year_text = date("F \'y", $next_year); 
    $data['next_year_text']= $next_year_text; 
    $previous_year = mktime(0,0,0,$current_month,1,$current_year-1); 
    $data['previous_year']=$previous_year; 
    $previous_year_text = date("F \'y", $previous_year); 
    $data['previous_year_text']= $previous_year_text; 
     } 

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

其中$塞返回月份爲下一首/上

相關問題