2012-01-19 17 views
0

次の長いコードを使用して今後の予定をリストします。イベントを表示する日数を10日とし、その10日間に多くのイベントをグループ化します。コードを変更して、各イベントの日付が表示されるのではなく、複数のイベントがある特定の日付のヘッダーが1つだけになるようにしました。しかし、それはまだ私に次の10日間のすべての出来事を与える。次の10日間の多数のイベントのうち、6イベントだけを返す/表示する/出力するように、コードを制限したいと思います。 for ($i=0; $i<$days_to_display; $i++) しかし$days_to_displayビットは、それがトリッキーになり:PHP#をループしてループしますが、出力の数を制限したい場合は

私は変更する必要があるものをかなり確信しているがここにあります。

ご協力いただければ幸いです!

<?php 

// List View of Coming Events v .9 
// Plug-in for PHPiCalendar 2.0/2.1 
// developed by Johnathon Wright (my initials @ mustmodify.com) 

// Original Publication Date: 2005 10 28 
// Originally Developed for St. Barnabas Episcopal Church website 

// Include this file from your PHP-enabled front page. 
// Do something like this: 
// <?PHP include 'd:/inetpub/.../phpical/event_list.php'; 

// DEFINE the base PHPiCalendar directory below. 
define('BASE', 'c:/inetpub/ouhsd.k12.ca.us/phpicalendar/'); 

// create an actual PHPiCalendar instance 
require_once(BASE.'functions/ical_parser.php'); 
require_once(BASE.'functions/list_functions.php'); 
require_once(BASE.'functions/template.php'); 
header("Content-Type: text/html; charset=$charset"); 

// at this point, the calendar has been generated and its data 
// is stored in $master_array. Test to ensure that this is working by 
// un-commenting the lines below. 

/* 
echo "<pre>"; 
print_r($master_array); 
echo "</pre>"; 
*/ 

// A few settings... 

// days_to_display_default should be a positive integer. 
$days_to_display_default = 14; 

// SHOW PRIVATE EVENTS {TRUE, FALSE} 
// In Mozilla Sunbird, events can be set to PRIVATE. 
// PHPiCalendar does not display the title or description for 
// these events, but does display the time, if applicable. 
// If you want to hide these events, set $show_private_events to FALSE. 
// Otherwise, it should be TRUE 

$show_private_events = TRUE; 

// day_to_begin should be a text string. See http://www.php.net/strtotime 
// for full documentation. Some values I tested: 
// ------------------------------------------------------- 
// last monday - the most recent Monday. 
// thursday - this gave me the date of the next Wednesday. 
// yesterday - yesterday 
// today - today 
// next week - +2 weeks (How can this be? Don't ask me, it's PHP...) 
// 1 week - a week from today 

$day_to_begin = "today"; 


// Replace with the commented code if you would NOT like 
// users to be able to set this value on their own. 



$days_to_display = $days_to_display_default; 

/* 

// this code replaces the above code if you want to prevent 
// users from setting the number of days to display 

$days_to_display = $days_to_display_default; 

*/ 


// This next section seems terribly inefficient. We calculate the unix 
// timestamp of first-thing-this-morning by finding out the date 
// and then looking up the timestamp for that date... 

// Again, the commented code prevents users from setting their own start date. 


$date_start = date('Ymd', strtotime("now")); 
$timestamp_start = strtotime(dateOfWeek($getdate, $date_start)); 

/* 
$date_start = date('Ymd', strtotime("now")); 
$timestamp_start = strtotime(dateOfWeek($getdate, $date_start)); 
*/ 

// Display the date range for this list 

$timestamp_end = $timestamp_start + ($days_to_display * 24 * 60 * 60); 

// seed the iterator $thisdate with todays timestamp. 
// It will loop through $days_to_display... 

$thisdate = $timestamp_start; 

// Loop through the days, finding events in each day 

for ($i=0; $i<$days_to_display; $i++) 
    { 

    $thisday = date("Ymd", $thisdate); 

    if (isset($master_array[$thisday])) 
     { 
     echo "<br/>"; 

     foreach($master_array[($thisday)] as $event_start_time => $event_set) 
     { 
     foreach ($event_set as $event_id => $event_info) 
      { 
      // Where are we? 
      // date is $thisdate 
      // time is $event_start_time 
      // event is $event_id; 

      if (! (($event_info['event_text'] == '**PRIVATE**') && ($show_private_events == FALSE))) 
       { 
// event title 
       echo "<li>"; 
       echo "<span class='bold_text'>" . stripslashes(urldecode($event_info['event_text'])) . "</span><br/>"; 


// event time range, if not an all-day event 
       echo " <span style='display: block;'>". date("D. F jS", $thisdate) . ""; 

       if (! (($event_info['event_start'] == '0000') && ($event_info['event_end'] == '0000'))) 
        { 
        echo ": 
" . date("g:ia", $event_info['start_unixtime']) . " - " . date("g:ia", $event_info['end_unixtime'])."</span>"; 
        } 

// event location 
       if (strlen($event_info['location']) > 0) 
        { 
        echo " <span class='italic_text'>" . stripslashes(urldecode($event_info['location'])) . "</span>"; 
        } 


       /* 
       if ((($event_info['event_start'] == '0000') && ($event_info['event_end'] == '0000'))) 
        { 
        echo "all day"; 
        }*/ 

       // event description. 

       echo "</li>"; 
       } // IF private event AND we don't want to see those 
      }// END enter this event 
     } // END foreach event 
     } // END if there are any events today in the array 

    // iterator should be the next day. 
    // Why is this 25? Shouldn't it be 24? 
    $thisdate = ($thisdate + (25 * 60 * 60)); 
    } 



?> 

答えて

0

出力されたどのように多くのイベントを追跡するためにどこかにカウンターを入れて、あなたが限界に達するとループを終了:

$limit = 6; 
$displayed = 0; 

foreach(...) { 
    if (show_event()) { 
     ... show event ... 
     $displayed++; 
     if ($displayed >= $limit) { 
      break; 
     } 
    } 
} 
+0

私はこれを動作させることができませんでした。それでも、イベントは表示されず、表示される日数が制限されます。私はコードの周りすべてを移動し、それは私が得た唯一の効果でした。 :/それはユーザーエラーかもしれませんが –

0

これが最善の方法ではないかもしれません!しかし、あなたはforeachの上に別のループを追加することができます:

for ($i=0; $i<$days_to_display; $i++) 
    { 

     $thisday = date("Ymd", $thisdate); 

     if (isset($master_array[$thisday])) 
    { 
      echo "<br/>"; 

    for($k=0;$k<=$noofevents;$k++) //Where $noofevents is the number of events! 
    { 
foreach($master_array[($thisday)] as $event_start_time => $event_set) 
    { 
    foreach ($event_set as $event_id => $event_info) 
     { 
     // Where are we? 
     // date is $thisdate 
     // time is $event_start_time 
     // event is $event_id; 

     if (! (($event_info['event_text'] == '**PRIVATE**') && ($show_private_events == FALSE))) 
      { 
// event title 
      echo "<li>"; 
      echo "<span class='bold_text'>" . stripslashes(urldecode($event_info['event_text'])) . "</span><br/>"; 


// event time range, if not an all-day event 
      echo " <span style='display: block;'>". date("D. F jS", $thisdate) . ""; 

      if (! (($event_info['event_start'] == '0000') && ($event_info['event_end'] == '0000'))) 
       { 
       echo ": 
" . date("g:ia", $event_info['start_unixtime']) . " - " . date("g:ia", $event_info['end_unixtime'])."</span>"; 
       } 

// event location 
      if (strlen($event_info['location']) > 0) 
       { 
       echo " <span class='italic_text'>" . stripslashes(urldecode($event_info['location'])) . "</span>"; 
       } 


      /* 
      if ((($event_info['event_start'] == '0000') && ($event_info['event_end'] == '0000'))) 
       { 
       echo "all day"; 
       }*/ 

      // event description. 

      echo "</li>"; 
      } // IF private event AND we don't want to see those 
     }// END enter this event 
    } // END foreach event 
    } // END for x events 
    } //END if isset 
}//END for days 
+0

私はこれを試したときに何も表示されません。私はそれが働くには$ days_todisplay行が必要だと思います。知りません?試してくれてありがとう。 –

+0

はい、前と後のコードはすべて同じでなければなりません。この場所に追加するだけです。現在のコードを削除しないでください。正常に動作するはずです。 – Zac

+0

貼り付けをコピーできるようにコードを編集しましたが、かっこを再確認する必要があります – Zac

関連する問題