Forum Moderators: coopster
it changes an image depending on the time and day put into the array
<?php
$air_status = 'Non Stop Music';
$img_src = '../../images/air/nonstop.png';
$air_times = array(
//Monday Times, Remeber -1 on hours, Top hour is the start off Monday
array('day' => 'Sunday', 'start' => 23 * 60 + 00, 'end' => 23 * 60 + 59, 'status' => 'Booshish', 'img_src' => '../../images/air/booshish.png'),
array('day' => 'Monday', 'start' => 00 * 60 + 00, 'end' => 00 * 60 + 59, 'status' => '1s @ 1', 'img_src' => '../../images/air/1s_at_1.png')
);
date_default_timezone_set('GMT');
$c_day = date('l');
$time = date('G') * 60 + date('i');
foreach ($air_times as $slot) {
if ($slot['day'] == $c_day && $slot['start'] <= $time && $slot['end'] >= $time) {
$air_status = $slot['status'];
$img_src = $slot['img_src'];
}
}
print " <img src='{$img_src}' alt='{$air_status}' title='{$air_status}' >";
//print date('G') . ':' . date('i') . ' on ' . date('l');
?>
as you can see its alot of codes since it would be for each day of the week for each time, and if a show changes it means someone has to go into the code,
i was working on adding it to a database, i have come up to this but cant seem to get it to work, was wondering if someone can help
(the fields of database are all used within the code)
thanks alot
<?php
$q=mysql_query("SELECT * FROM schedule WHERE live='yes' ORDER BY onair_day DESC",$c) or die(mysql_error());
$air_status = 'Non Stop Music';
$img_src = 'images/air/nonstop.png';
while($r2=mysql_fetch_array($q))
{
$air_times = array("day" => "{$r2['onair_day']}", "start" => "{$r2['ostart_hr']}" * 60 + "{$r2['ostart_min']}", 'end' => "{$r2['ofinish_hr']}" * 60 + "{$r2['ofinish_min']}", "status" => "{$r2['name']}", "img_src" => "images/air/{$r2['showimg']}");
}
date_default_timezone_set('GMT');
$c_day = date('l');
$time = date('G') * 60 + date('i');
foreach ($air_times as $slot) {
if ($slot['day'] == $c_day && $slot['start'] <= $time && $slot['end'] >= $time)
{
$air_status = $slot['status'];
$img_src = $slot['img_src'];
}
}
print " <img src='{$img_src}' alt='{$air_status}' title='{$air_status}' >";
?>
date_default_timezone_set('GMT');
$c_day = date('l');
$time = date('G') * 60 + date('i');
while($r2=mysql_fetch_array($q))
{
$air_times = array('day' => $r2['onair_day'], 'start' => $r2['ostart_hr'] * 60 + $r2['ostart_min'], 'end' => $r2['ofinish_hr'] * 60 + $r2['ofinish_min'], 'status' => $r2['name'], 'img_src' => images/air/{$r2['showimg']);
//see what your values are print_r($air_time);
if ($air_time['day'] == $c_day && $air_time['start'] <= $time && $air_time['end'] >= $time)
{
$air_status = $air_time['status'];
$img_src = $air_time['img_src'];
}
}
echo "<img src=\$img_src\" alt=\$air_status\" title=\"$air_status\">";
ya am geting an error
"
Warning: Division by zero in /home/kcclive/public_html/new kcclive/sections/topsection.php on line 82"
the line 82 is the array line
$air_times = array('day' => $r2['onair_day'], 'start' => $r2['ostart_hr'] * 60 + $r2['ostart_min'], 'end' => $r2['ofinish_hr'] * 60 + $r2['ofinish_min'], 'status' => $r2['name'], 'img_src' => images/air/{$r2['showimg']);
ps thanks for your help
Try this one
$air_times = array('day' => $r2['onair_day'], 'start' => $r2['ostart_hr'] * 60 + $r2['ostart_min'], 'end' => $r2['ofinish_hr'] * 60 + $r2['ofinish_min'], 'status' => $r2['name'], 'img_src' => "images/air/"$r2['showimg']);
here is the site so you can see it working (it changes every hour)
(new kcclive, as this is where the sites run from database in a temp location)
but for anyone else who may need this, heres the full code
<?php
$q=mysql_query("SELECT * FROM schedule WHERE live='yes' ORDER BY onair_day DESC",$c) or die(mysql_error());
date_default_timezone_set('GMT');
$c_day = date('l');
$time = date('G') * 60 + date('i');
while($r2=mysql_fetch_array($q))
{
$air_time = array('day' => $r2['onair_day'], 'start' => $r2['ostart_hr'] * 60 + $r2['ostart_min'], 'end' => $r2['ofinish_hr'] * 60 + $r2['ofinish_min'], 'status' => $r2['name'], 'img_src' => "images/air/".$r2['showimg']);
//see what your values are print_r($air_time);
if ($air_time['day'] == $c_day && $air_time['start'] <= $time && $air_time['end'] >= $time)
{
$air_status = $air_time['status'];
$img_src = $air_time['img_src'];
}
else
{
$air_status = 'Non Stop Music';
$img_src = '../../images/air/nonstop.png';
}
}
echo "<img src=\"$img_src\" alt=\"$air_status\" title=\"$air_status\">";
//print date('G') . ':' . date('i') . ' on ' . date('l');
?>
thanks alot Skinsey for all your help
[edited by: eelixduppy at 5:01 pm (utc) on Oct. 17, 2009]
[edit reason] no URLs, please [/edit]
<?
include("include/connect.php");
$query5 = "SELECT * FROM hangsmartcompany";
$temp5 = mysql_query($query5)
or die(mysql_error());
<?php
$q=mysql_query("SELECT * FROM schedule WHERE live='yes' ORDER BY onair_day DESC",$c) or die(mysql_error());
date_default_timezone_set('GMT');
$c_day = date('l');
$time = date('G') * 60 + date('i');
while($r2=mysql_fetch_array($q))
{
$air_time = array('day' => $r2['onair_day'], 'start' => $r2['ostart_hr'] * 60 + $r2['ostart_min'], 'end' => $r2['ofinish_hr'] * 60 + $r2['ofinish_min'], 'status' => $r2['name'], 'img_src' => "images/air/".$r2['showimg']);
//see what your values are print_r($air_time);
if ($air_time['day'] == $c_day && $air_time['start'] <= $time && $air_time['end'] >= $time)
{
$air_status = $air_time['status'];
$img_src = $air_time['img_src'];
}
}
if (empty($air_status))
{
$air_status = 'Non Stop Music';
$img_src = '../../images/air/nonstop.png';
}
echo "<img src=\"$img_src\" alt=\"$air_status\" title=\"$air_status\">";
//print date('G') . ':' . date('i') . ' on ' . date('l');
?>