Next Increment in an Array

I’ve made up a script for a music festival web site that will show who is onstage at the time that a user accesses the site. The script works fine so far, but I’m wondering if I could add an “Up Next” line somehow.

Can anyone help?

[php]<?php
date_default_timezone_set(“America/Menominee”);
$time_start = (date(‘mdYh:iA’));
$time_end = (date(‘mdYh:iA’));
// the date, start and end must be edited to test this script
$acts = array(
array(
‘name’ => ‘Band #1’,
‘stage’=> ‘Small’,
‘date’ => ‘06202011’,
‘start’ => ‘04:15PM’,
‘end’ => ‘04:20PM’
),
array(
‘name’ => ‘Band #2’,
‘stage’=> ‘Main’,
‘date’ => ‘06202011’,
‘start’ => ‘04:20PM’,
‘end’ => ‘04:25PM’
),
array(
‘name’ => ‘Band #3’,
‘stage’=> ‘Galactic’,
‘date’ => ‘06202011’,
‘start’ => ‘04:25PM’,
‘end’ => ‘04:40PM’
)
);

foreach ($acts as $act) {
foreach($act as $key => $value) {
if ($time_start = $act[‘date’].$act[‘start’] && $time_end < $act[‘date’].$act[‘end’]) {
echo $act[‘name’].’ is on the ‘.$act[‘stage’].’ Stage.’;
break;
}
}

}

?>[/php]

try this : (i have changed start and end and date for my testing purpose… kindly revert back the values)

[php]<?php
date_default_timezone_set(“America/Menominee”);
$time_start = (date(‘mdYh:iA’));
$time_end = (date(‘mdYh:iA’));
// the date, start and end must be edited to test this script
$acts = array(
array(
‘name’ => ‘Band #1’,
‘stage’=> ‘Small’,
‘date’ => ‘06242011’,
‘start’ => ‘01:15PM’,
‘end’ => ‘04:20PM’
),
array(
‘name’ => ‘Band #2’,
‘stage’=> ‘Main’,
‘date’ => ‘06252011’,
‘start’ => ‘01:20PM’,
‘end’ => ‘04:25PM’
),
array(
‘name’ => ‘Band #3’,
‘stage’=> ‘Galactic’,
‘date’ => ‘06262011’,
‘start’ => ‘01:25PM’,
‘end’ => ‘04:40PM’
)
);

foreach ($acts as $lock => $act) {
foreach($act as $key => $value) {
if($up_next == 1 && !($time_start > $act[‘date’].$act[‘start’] && $time_end < $act[‘date’].$act[‘end’])){
echo ’
Up Next : ‘.$act[‘name’].’ will perform on the ‘.$act[‘stage’].’ Stage at ‘.$act[‘start’];
$up_next = 0;
}
if ($time_start > $act[‘date’].$act[‘start’] && $time_end < $act[‘date’].$act[‘end’]) {
echo $act[‘name’].’ is on the ‘.$act[‘stage’].’ Stage.’;
$current_flag = 1;
break;
}
}
if($current_flag == 1){
$current_flag = 0;
$up_next = 1;
}
}
?>
[/php]

That does the trick, thanks! Now to analyze your code to see if I can figure out how you did it… ;D

Sponsor our Newsletter | Privacy Policy | Terms of Service