| View previous topic :: View next topic |
| Author |
Message |
kiwi_dude
Joined: 05 Jun 2006 Posts: 25
|
Posted: Tue Jan 16, 2007 12:17 am Post subject: Limit get_event_list? |
|
|
Hi Ian,
I am using the $cal->get_event_list("day"); function to return the events on today.
Unfortuanately, I have some days that have upwards of 50 events happening. How can I limit the number of events that are returned (or displayed) for that day using this code ie 10, 15 etc?
This is the code I am using (provided by you of course):
$elist = $cal->get_event_list("day");
// before anything ..
$events_printed = 0;
# each day returned in this list
foreach($elist as $d) {
# each event on this day
foreach($d as $e) {
$events_printed = 1;
# Get full event details
$e = $cal->get_event($e['id'],$e['instance']);
if ($e->notes == "") $notes = "No Details Given";
else $notes = $e->notes;
echo("id."&instance=2007-1-19&KeepThis=true&TB_iframe=true&height=300&width=500\">".$e->title." ".$cal->format_date("D M j",$e->start).""
);
} |
|
| Back to top |
|
 |
esoft_kent
Joined: 11 Jan 2007 Posts: 143
|
Posted: Tue Jan 16, 2007 7:10 pm Post subject: |
|
|
You can limit the display by using a different type of for loop.
Change this:
| Code: |
# each day returned in this list
foreach($elist as $d) {
# each event on this day
foreach($d as $e) {
$events_printed = 1;
# Get full event details
$e = $cal->get_event($e['id'],$e['instance']); |
to this (replace '15' with whatever max number you want):
| Code: |
# each day returned in this list
foreach($elist as $d) {
# each event on this day
for ($i = 0; $i < 15; $i++ ) {
$e = $d[$i];
$events_printed = 1;
# Get full event details
$e = $cal->get_event($e['id'],$e['instance']); |
Kent
edit: There's more info on control loop structures here: http://us3.php.net/manual/en/control-structures.for.php |
|
| Back to top |
|
 |
kiwi_dude
Joined: 05 Jun 2006 Posts: 25
|
Posted: Tue Jan 16, 2007 10:27 pm Post subject: |
|
|
Hi Ken,
Thanks for the code, unfortunatley the 'for' loop doeas not work correcty in place of the 'foreach' loop in this circumstance (i get a large list of just "event" items - much longer than 15)
Any other ideas??
Cheers
Dean |
|
| Back to top |
|
 |
esoft_ian
Joined: 12 Sep 2005 Posts: 5275
|
Posted: Tue Jan 16, 2007 10:50 pm Post subject: |
|
|
Hi,
Try:
| Code: |
$limit = 15;
# each day returned in this list
foreach($elist as $d) {
if(!$limit) break;
# each event on this day
foreach($d as $e) {
if(!$limit--) break;
$events_printed = 1;
# Get full event details
$e = $cal->get_event($e['id'],$e['instance']);
|
|
|
| Back to top |
|
 |
kiwi_dude
Joined: 05 Jun 2006 Posts: 25
|
Posted: Wed Jan 17, 2007 1:00 am Post subject: |
|
|
Almost got it..
| Code: |
// before anything ..
$events_printed = 0;
$limit = 10;
# each day returned in this list
foreach($elist as $d) {
if(!$limit) break;
# each event on this day
foreach($d as $e) {
if(!$limit--) break
$events_printed = 1;
# Get full event details
$e = $cal->get_event($e['id'],$e['instance']);
# print event title
//echo("title."&instance=2007-1-19\">".$e->title."");
if ($e->notes == "") $notes = "No Details Given";
else $notes = $e->notes;
echo("id."&instance=".$e->instance."&KeepThis=true&TB_iframe=true&height=310&width=520\">".$e->title.""
);
}
}
if(!$events_printed ) {
echo("No Upcoming Events (The Next 2 Weeks)");
echo("Calendar...");
}
else {
echo("More...");
} |
This prints out 10 items. but also prints the "No Upcoming Events (The Next 2 Weeks)", even though $events_printed should equal 1?
Thanks for your assistance..much appreciated
Cheers |
|
| Back to top |
|
 |
esoft_kent
Joined: 11 Jan 2007 Posts: 143
|
Posted: Wed Jan 17, 2007 6:09 pm Post subject: |
|
|
Hmmm, guess I had something not quite right .
Ian's code looks great, too - cleaner. Try putting a semicolon after the line
so that it reads
That seemed to fix it for me. |
|
| Back to top |
|
 |
kiwi_dude
Joined: 05 Jun 2006 Posts: 25
|
Posted: Wed Jan 17, 2007 9:39 pm Post subject: |
|
|
Thanks Kent, all working  |
|
| Back to top |
|
 |
|