Forum Moderators: coopster

Message Too Old, No Replies

image changer

         

xida

1:13 pm on Oct 15, 2009 (gmt 0)

10+ Year Member



hi, i currently have this code within my site, its for a radio website

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}' >";
?>

skinsey

8:13 am on Oct 16, 2009 (gmt 0)

10+ Year Member



I didn't test this but I think this is what your looking for. Use it on a test page and let me know how it works. If it fails.
Uncomment the line and use the print_r($air_time); to see your value before it hits the if statement. Put errors and values in reply

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\">";

skinsey

8:15 am on Oct 16, 2009 (gmt 0)

10+ Year Member



after images/air/ remove the {

skinsey

8:18 am on Oct 16, 2009 (gmt 0)

10+ Year Member



Missed this also

echo "<img src=\"$img_src\" alt=\"$air_status\" title=\"$air_status\">";

xida

9:15 am on Oct 16, 2009 (gmt 0)

10+ Year Member



cool thanks alot for that,

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

skinsey

9:44 am on Oct 16, 2009 (gmt 0)

10+ Year Member



The only place that I would think it thinks it could be division is for the image.

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']);

xida

9:56 am on Oct 16, 2009 (gmt 0)

10+ Year Member



geting this error on the same page now :S

Parse error: syntax error, unexpected T_VARIABLE, expecting ')' in /home/kcclive/public_html/new kcclive/sections/topsection.php on line 81

skinsey

9:57 am on Oct 16, 2009 (gmt 0)

10+ Year Member



Tested it it still errored out
this fixed it

$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']);

xida

10:08 am on Oct 16, 2009 (gmt 0)

10+ Year Member



thanks alot thats really helped alot

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]

skinsey

10:11 am on Oct 16, 2009 (gmt 0)

10+ Year Member



Glad it worked :)

skinsey

10:38 am on Oct 16, 2009 (gmt 0)

10+ Year Member



Just looked over your code the else statement is still in your while loop so if the last array is false then it will set it to non stop music. It needs to check after the loop is done. Take care.

<?
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');

?>

xida

12:45 pm on Oct 16, 2009 (gmt 0)

10+ Year Member



thanks alot :) thought i might have done that wrong lol