Jump to content

Recommended Posts

I downloaded this script of the net but I can't get it to work for me. the scrip is suppose to output a picture based on the time of day, but nothing happens. I need it to read the server's clock so that people all over the world will hear the DJ that the website indicates.

 

the script (in a file called "picture.php" within the site's root directory)

 

<?php

$h = date('G'); //set variable $h to the hour of the day

$d = date('w'); //set variable $d to the day of the week.

$year = date('Y'); //set variable $year to the current year

//G is the date key for hours in 24 format (not 12), with no leading 0s, like 02.

// Adjust 2 hour offset for MST below.

$h = $h-2;

 

//G is the date key for hours in 24 format (not 12), with no leading 0s, like 02.

 

// SUN SCHEDULE

if ($d == 0 && $h >= 8 && $h < 10) { $img = 'images/talent_images/onairkeplersmooth.jpg';

else if ($d == 0 && $h >= 10 && $h < 12) { $img = 'images/talent_images/onairkepler20.jpg';

else if ($d == 0 && $h >= 12 && $h < 16) { $img = 'images/talent_images/onairkenny.jpg';

else if ($d == 0 && $h >= 16 && $h < 21) { $img = 'images/talent_images/onairnorman.jpg';

else if ($d == 0 && $h >= 21 && $h < 23) { $img = 'images/talent_images/onairpaul.jpg';

else if ($d == 0 && $h >= 23) { $img = 'images/talent_images/onairmaria.jpg';

else if ($d == 1 && $h < 0) { $img = 'images/talent_images/onairmaria.jpg';

 

// MON SCHEDULE

if ($d == 1 && $h >= 0 && $h < 8) { $img = 'images/talent_images/onairmaria.jpg';

else if ($d == 1 && $h >= 8 && $h < 12) { $img = 'images/talent_images/onairkennysandy.jpg';

else if ($d == 1 && $h >= 12 && $h < 14) { $img = 'images/talent_images/onairmiranda.jpg';

else if ($d == 1 && $h >= 14 && $h < 21) { $img = 'images/talent_images/onairdave.jpg';

else if ($d == 1 && $h >= 21 && $h < 23) { $img = 'images/talent_images/onairmaria.jpg';

else if ($d == 1 && $h >= 23) { $img = 'images/talent_images/onairmaria.jpg';

else if ($d == 2 && $h < 0) { $img = 'images/talent_images/onairmaria.jpg';

 

// TUES SCHEDULE

if ($d == 2 && $h >= 0 && $h < 8) { $img = 'images/talent_images/onairmaria.jpg';

else if ($d == 2 && $h >= 8 && $h < 12) { $img = 'images/talent_images/onairkennysandy.jpg';

else if ($d == 2 && $h >= 12 && $h < 14) { $img = 'images/talent_images/onairmiranda.jpg';

else if ($d == 2 && $h >= 14 && $h < 21) { $img = 'images/talent_images/onairdave.jpg';

else if ($d == 2 && $h >= 21 && $h < 23) { $img = 'images/talent_images/onairmaria.jpg';

else if ($d == 2 && $h >= 23) { $img = 'images/talent_images/onairmaria.jpg';

else if ($d == 3 && $h < 0) { $img = 'images/talent_images/onairmaria.jpg';

 

// WEDS SCHEDULE

if ($d == 3 && $h >= 0 && $h < 8)  $img = 'images/talent_images/onairmaria.jpg';

else if ($d == 3 && $h >= 8 && $h < 12)  $img = 'images/talent_images/onairkennysandy.jpg';

else if ($d == 3 && $h >= 12 && $h < 14)  $img = 'images/talent_images/onairmiranda.jpg';

else if ($d == 3 && $h >= 14 && $h < 21)  $img = 'images/talent_images/onairdave.jpg';

else if ($d == 3 && $h >= 21 && $h < 23)  $img = 'images/talent_images/onairmaria.jpg';

else if ($d == 3 && $h >= 23)  $img = 'images/talent_images/onairmaria.jpg';

else if ($d == 4 && $h < 0)  $img = 'images/talent_images/onairmaria.jpg';

 

// THURS SCHEDULE

if ($d == 4 && $h >= 0 && $h < 8) { $img = 'images/talent_images/onairmaria.jpg';

else if ($d == 4 && $h >= 8 && $h < 12) { $img = 'images/talent_images/onairkennysandy.jpg';

else if ($d == 4 && $h >= 12 && $h < 14) { $img = $img = 'images/talent_images/onairmiranda.jpg';

else if ($d == 4 && $h >= 14 && $h < 21) { $img = 'images/talent_images/onairdave.jpg';

else if ($d == 4 && $h >= 21 && $h < 23) { $img = 'images/talent_images/onairmaria.jpg';

else if ($d == 4 && $h >= 23) { $img = 'images/talent_images/onairmaria.jpg';

else if ($d == 5 && $h < 0) { $img = 'images/talent_images/onairmaria.jpg';

 

// FRI SCHEDULE

if ($d == 5 && $h >= 0 && $h < 8) { $img = 'images/talent_images/onairmaria.jpg';

else if ($d == 5 && $h >= 8 && $h < 12) { $img = 'images/talent_images/onairkennysandy.jpg';

else if ($d == 5 && $h >= 12 && $h < 14) { $img = 'images/talent_images/onairmiranda.jpg';

else if ($d == 5 && $h >= 14 && $h < 21) { $img = 'images/talent_images/onairdave.jpg';

else if ($d == 5 && $h >= 21 && $h < 23) { $img = 'images/talent_images/onairmaria.jpg';

else if ($d == 5 && $h >= 23) { $img = 'images/talent_images/onairmaria.jpg';

else if ($d == 6 && $h < 0) { $img = 'images/talent_images/onairmaria.jpg';

 

 

// SAT SCHEDULE

if ($d == 0 && $h >= 8 && $h < 10) { $img = 'images/talent_images/onairkeplersmooth.jpg';

else if ($d == 6 && $h >= 10 && $h < 12) { $img = 'images/talent_images/onairkepler20.jpg';

else if ($d == 6 && $h >= 12 && $h < 16) { $img = 'images/talent_images/onairkenny.jpg';

else if ($d == 6 && $h >= 16 && $h < 21) { $img = 'images/talent_images/onairnorman.jpg';

else if ($d == 6 && $h >= 21 && $h < 23) { $img = 'images/talent_images/onairpaul.jpg';

else if ($d == 6 && $h >= 23) { $img = 'images/talent_images/onairmaria.jpg';

else if ($d == 0 && $h < 0) { $img = 'images/talent_images/onairmaria.jpg';

 

echo '<a href="http://www.smoothjazznetwork.com"><img src="'.$img.'"></a>';

 

?>

 

 

then inside the html page where I want the pictures to show:

 

<?php require ("picture.php"); ?>

 

 

Please help, I'm at the end of my rope.

 

 

When posting code, please enclose it within the forum's

 . . . 

BBCode tags. That way it remains compact and gets highlighted like below.

 

You've left every one of the curly braces unclosed in all of your if/elseif statements. That should clear up the parse errors, adn then you can see if it produces the result you want.

<?php
if ($d == 0 && $h >= 8 && $h < 10) { $img = 'images/talent_images/onairkeplersmooth.jpg'; }
else if ($d == 0 && $h >= 10 && $h < 12) { $img = 'images/talent_images/onairkepler20.jpg'; }
else if ($d == 0 && $h >= 12 && $h < 16) { $img = 'images/talent_images/onairkenny.jpg'; }
else if ($d == 0 && $h >= 16 && $h < 21) { $img = 'images/talent_images/onairnorman.jpg'; }
else if ($d == 0 && $h >= 21 && $h < 23) { $img = 'images/talent_images/onairpaul.jpg'; }
else if ($d == 0 && $h >= 23) { $img = 'images/talent_images/onairmaria.jpg'; }
else if ($d == 1 && $h < 0) { $img = 'images/talent_images/onairmaria.jpg'; }

 

You should really be doing development with error_reporting = -1 and display_errors = On in your php.ini file. It would save you a lot of time to have errors like this reported.

I actually took those brackets off thinking they were the problem. The script didn't work with them in the file, but I will try again.

 

Furthermore, I am not aware of a php.ini file. where would I find that? Forgive my ignorance.

 

Your point about the enclosing my codes is well taken.

If you create a new script and in it place the following code, it will list the location of the php.ini file that is being used by php. Keep in mind that display_errors should be used when developing, but on a live, production server, you'd want to log them instead.

<?php
phpinfo();
?>

Still no output... my php file as it stands now

 


<?php
$h = date('G'); //set variable $h to the hour of the day
$d = date('w'); //set variable $d to the day of the week.
$year = date('Y'); //set variable $year to the current year
//G is the date key for hours in 24 format (not 12), with no leading 0s, like 02.
// Adjust 2 hour offset for MST below.
$h = $h-2; 

//G is the date key for hours in 24 format (not 12), with no leading 0s, like 02.

// SUN SCHEDULE
if ($d == 0 && $h >= 8 && $h < 10) { $img = 'images/talent_images/onairkeplersmooth.jpg'; }
else if ($d == 0 && $h >= 10 && $h < 12) { $img = 'images/talent_images/onairkepler20.jpg'; }
else if ($d == 0 && $h >= 12 && $h < 16) { $img = 'images/talent_images/onairkenny.jpg'; }
else if ($d == 0 && $h >= 16 && $h < 21) { $img = 'images/talent_images/onairnorman.jpg'; }
else if ($d == 0 && $h >= 21 && $h < 23) { $img = 'images/talent_images/onairpaul.jpg'; }
else if ($d == 0 && $h >= 23) { $img = 'images/talent_images/onairmaria.jpg'; }
else if ($d == 1 && $h < 0) { $img = 'images/talent_images/onairmaria.jpg'; }

// MON SCHEDULE
if ($d == 1 && $h >= 0 && $h <  { $img = 'images/talent_images/onairmaria.jpg'; }
else if ($d == 1 && $h >= 8 && $h < 12) { $img = 'images/talent_images/onairkennysandy.jpg'; }
else if ($d == 1 && $h >= 12 && $h < 14) { $img = 'images/talent_images/onairmiranda.jpg'; }
else if ($d == 1 && $h >= 14 && $h < 21) { $img = 'images/talent_images/onairdave.jpg'; }
else if ($d == 1 && $h >= 21 && $h < 23) { $img = 'images/talent_images/onairmaria.jpg'; }
else if ($d == 1 && $h >= 23) { $img = 'images/talent_images/onairmaria.jpg'; }
else if ($d == 2 && $h < 0) { $img = 'images/talent_images/onairmaria.jpg'; }

// TUES SCHEDULE
if ($d == 2 && $h >= 0 && $h <  { $img = 'images/talent_images/onairmaria.jpg'; }
else if ($d == 2 && $h >= 8 && $h < 12) { $img = 'images/talent_images/onairkennysandy.jpg'; }
else if ($d == 2 && $h >= 12 && $h < 14) { $img = 'images/talent_images/onairmiranda.jpg'; }
else if ($d == 2 && $h >= 14 && $h < 21) { $img = 'images/talent_images/onairdave.jpg'; }
else if ($d == 2 && $h >= 21 && $h < 23) { $img = 'images/talent_images/onairmaria.jpg'; }
else if ($d == 2 && $h >= 23) { $img = 'images/talent_images/onairmaria.jpg'; }
else if ($d == 3 && $h < 0) { $img = 'images/talent_images/onairmaria.jpg'; }

// WEDS SCHEDULE
if ($d == 3 && $h >= 0 && $h <  { $img = 'images/talent_images/onairmaria.jpg'; }
else if ($d == 3 && $h >= 8 && $h < 12) { $img = 'images/talent_images/onairkennysandy.jpg'; }
else if ($d == 3 && $h >= 12 && $h < 14) { $img = 'images/talent_images/onairmiranda.jpg'; }
else if ($d == 3 && $h >= 14 && $h < 21) { $img = 'images/talent_images/onairdave.jpg'; }
else if ($d == 3 && $h >= 21 && $h < 23) { $img = 'images/talent_images/onairmaria.jpg'; }
else if ($d == 3 && $h >= 23) { $img = 'images/talent_images/onairmaria.jpg'; }
else if ($d == 4 && $h < 0) { $img = 'images/talent_images/onairmaria.jpg'; }

// THURS SCHEDULE
if ($d == 4 && $h >= 0 && $h <  { $img = 'images/talent_images/onairmaria.jpg'; }
else if ($d == 4 && $h >= 8 && $h < 12) { $img = 'images/talent_images/onairkennysandy.jpg'; } 
else if ($d == 4 && $h >= 12 && $h < 14) { $img = $img = 'images/talent_images/onairmiranda.jpg'; }
else if ($d == 4 && $h >= 14 && $h < 21) { $img = 'images/talent_images/onairdave.jpg'; }
else if ($d == 4 && $h >= 21 && $h < 23) { $img = 'images/talent_images/onairmaria.jpg'; }
else if ($d == 4 && $h >= 23) { $img = 'images/talent_images/onairmaria.jpg'; }
else if ($d == 5 && $h < 0) { $img = 'images/talent_images/onairmaria.jpg'; }

// FRI SCHEDULE
if ($d == 5 && $h >= 0 && $h <  { $img = 'images/talent_images/onairmaria.jpg'; }
else if ($d == 5 && $h >= 8 && $h < 12) { $img = 'images/talent_images/onairkennysandy.jpg'; } 
else if ($d == 5 && $h >= 12 && $h < 14) { $img = 'images/talent_images/onairmiranda.jpg'; }
else if ($d == 5 && $h >= 14 && $h < 21) { $img = 'images/talent_images/onairdave.jpg'; }
else if ($d == 5 && $h >= 21 && $h < 23) { $img = 'images/talent_images/onairmaria.jpg'; }
else if ($d == 5 && $h >= 23) { $img = 'images/talent_images/onairmaria.jpg'; }
else if ($d == 6 && $h < 0) { $img = 'images/talent_images/onairmaria.jpg'; }


// SAT SCHEDULE
if ($d == 0 && $h >= 8 && $h < 10) { $img = 'images/talent_images/onairkeplersmooth.jpg'; }
else if ($d == 6 && $h >= 10 && $h < 12) { $img = 'images/talent_images/onairkepler20.jpg'; }
else if ($d == 6 && $h >= 12 && $h < 16) { $img = 'images/talent_images/onairkenny.jpg'; }
else if ($d == 6 && $h >= 16 && $h < 21) { $img = 'images/talent_images/onairnorman.jpg'; }
else if ($d == 6 && $h >= 21 && $h < 23) { $img = 'images/talent_images/onairpaul.jpg'; }
else if ($d == 6 && $h >= 23) { $img = 'images/talent_images/onairmaria.jpg'; }
else if ($d == 0 && $h < 0) { $img = 'images/talent_images/onairmaria.jpg'; }

echo '<a href="http://www.smoothjazznetwork.com"><img src="'.$img.' width="200" height="76" "></a>';

?>

I'm using dreamweaver to edit. Do you mean that I should do a "live view" within dreamweaver (DW)? When I do that DW tells me that I'm trying to use a serverside script and that I need to set it up. It never works for me them DW just ends up displaying the text of the scrip in the viewing area.

 

That's amazing - it works for you.

 

What in the world am I missing here? Am I calling it correctly from my main page?

 

 <?php require ("picture.php"); ?> 

 

does there needs to some statement in the <head> of my page? how is the identical file working for you and not for me?

Php is a server-side scripting language. It gets added to a web server so that .php code will be parsed and interpreted on the server when .php pages are requested by the browser. DW has never been very server-side friendly.

 

You either need to install a web server with php on your local development computer (there are all-in-one packages, such as http://www.apachefriends.org/en/xampp.html ) or test your code on your 'live' web server.

When you call the page on the live server into your web browser, do a View--->Source and see if the html markup for the image:

 

<a href="http://www.smoothjazznetwork.com"><img src="'.$img.' width="200" height="76" "></a>

 

is anywhere to be found, and if it has one of the image filenames for the src= attribute.

It is nowhere to be found. This is what shows

 

 <td width="213" height="80" align="center" valign="middle"><?php require ("picture.php"); ?></td>
        <td width="385"><img src="images/listenlive.png" width="385" height="78" border="0" usemap="#Map3">
          <map name="Map3">  

 

it does not seem to be running picture.php

figured it out. the code was ok. Dreamweaver has a function to include a serverside script - I did that and it worked.  I can't tell you how much I appreciate your help and patience.

 

inside my webpage:

 

 <!--#include file="picture.php" --> 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.