2010-10-20 64 views
0

我有下面的腳本和網站http://cacrochester.com,有時右側邊欄的內容加載,有時他們沒有。我認爲,如果這是你在網頁上的第幾次,它會說沒有事件安排。有時內容加載,有時他們沒有

我完全難以理解爲什麼會發生這種情況。數據庫中的數據沒有變化。

讓我知道你是否需要我發佈任何代碼。

感謝您的幫助!

<?php 

      $dummy = 0; 
      $headingLength = 0; 
      $descriptionLength = 0; 
      $shortHeading = 0; 
      $shortDescription = 0; 
      $todayYear = date('Y'); 
      $todayMonth = date('m'); 
      $todayDay = date('d'); 
      $events = new dates(); 
      $noEvents = 0; 

      //get the number of upcoming events 
      $numEvents = $events->getNumberEvents(); 

      //get the actual events 
      $results = $events->getRows(); 

      //used if there are not at least 5 events to fill up the event scroller 
      switch($numEvents) { 
       case 1: $dummy = 4; break; 
       case 2: $dummy = 3; break; 
       case 3: $dummy = 2; break; 
       case 4: $dummy = 1; break; 
      } 

      //loops through all of the events in the table and adds them to the list 
      foreach($results as $result) 
      { 
       $strippedHeading = stripslashes($result['heading']); 
       $strippedDescription = stripslashes($result['description']); 
       $headingLength = strlen($strippedHeading); 
       $descriptionLength = strlen($strippedDescription); 
       $shortHeading = $strippedHeading; 
       $shortDescription = $strippedDescription; 
       $time = strftime("%l:%M %P", $result['time']); 
       $location = $result['location']; 
       $startDate = getdate($result['start_date']); 
       $today = getdate(); 

       //if the events are NOT in the past...   
       if($startDate >= $today) 
       {  
        //if we are at the end of the array, add the class 'last' to the li 
        if(current($result) == end($result)) 
        { 
         echo "<li class=\"last\"><a href=\"Calendar.php\"><h4>".$shortHeading."</h4><h6>$time</h6><h6>$location</h6></a></li>".PHP_EOL; 
        } 
        else 
        { 
         echo "<li><a href=\"Calendar.php\"><h4>".$shortHeading."</h4><h6>$time</h6><h6>$location</h6></a></li>".PHP_EOL; 
        }     
        $noEvents = 1; 
       } 

       //if there is not at least 5 events, it repeats the events in the list until there are 5 total 
       elseif($dummy > 0 && $numEvents > 0) 
       {     
        //if the events are NOT in the past... 
        if($startDate >= $today) 
        { 
         //if we are at the end of the array, add the class 'last' to the li 
         if($dummy == 0) 
         { 
          echo "<li class=\"last\"><a href=\"Calendar.php\"><h4>".$shortHeading."</h4> ".$shortDescription."</a></li>".PHP_EOL; 
          $dummy--; 
         } 
         else 
         { 
          echo "<li><a href=\"Calendar.php\"><h4>".$shortHeading."</h4> ".$shortDescription."</a></li>".PHP_EOL; 
          $dummy--; 
         } 

         //if we have 5 events, do not add anymore 
         if($dummy < 0) 
         { 
          break; 
         } 
        } 

        $noEvents = 1; 
       } 
      } 

      //if there are no events, display the no events message 
      if($noEvents == 0) 
      { 
       echo "<li class=\"last\"><a href=\"Calendar.php\"><h4>No Events Scheduled</h4></a></li>".PHP_EOL; 
      } 
      ?> 

回答

1

當你做$startDate >= $today你試圖比較兩個數組,這不是一個好主意。只需使用普通的時間戳和它應該很好地工作:

$startDate = $result['start_date']; 
$today = strtotime('today'); 

而且,我不知道這是否是一個錯字:current($result) == end($result),但它不應該是$results,這是數組名?

+0

是的應該是$結果,而不是$結果。你的回答也起作用。我忘了在這一點上停止了這一次的工作,我注意到它正在比較數組。謝謝! – Catfish 2010-10-21 00:07:40

相關問題