View Full Version : Old dog needs new trick.

01-14-2010, 05:32 PM
All my previous experience in websites has been either straight HTML, Javascript or ASP.

I am now being forced to use a server that does not support ASP but does support PHP. Unfortunately, I don't know the first thing about PHP.

What I am asking is if someone could post some sample code that would show me what I have to do in order to accomplish my goal, or lead me to somewhere where scripts already exist for this sort of thing. I think what I want to do is fairly simple.

Here is what I want to accomplish:

In a small section of a website for a greenhouse, I want an image to show under the heading, "What's in Bloom Now?"

The image would change according to the date on the viewers computer clock. I want the ability to change it weekly or monthly or maybe even quarterly depending on how often the people maintaining the site want to upload new stuff. Under the picture, I want a line or two of text that would change along with the picture according to the date.

So, for example, if Daisys bloom in April, Starting on April 1st and continuing until the next date with a selection entered, a picture of Daisys would appear and under them a line of text that says something like, "Please visit our greenhouse this April to see our great selection of Daisys".

Then in March, it would change.

Is this a database thing as well?

Any and all help is appreciated.

Thank you.

01-14-2010, 05:38 PM
The main issue here is you said you wanted to use "the viewer's computer clock". PHP is serverside and can't get the user's time. It can only get the server time. You can use javascript to pass the users time to the server and then php can spit out an image but then that might be come inefficient. What you want to do would be better done using javascript. However if you just need the month then you can use php without having to use javascript. PHP has date methods you can use. I seriously doubt a user will be in a different month than the server.

01-14-2010, 05:39 PM
I seriously doubt a user will be in a different month than the server.

...if for only a few hours at most, every 4-5 weeks or so. ;)

01-14-2010, 05:41 PM
...if for only a few hours at most, every 4-5 weeks or so. ;)

I guess thats true with the different time zones and what not.

01-14-2010, 05:43 PM
Bob ...

Several approaches to this, as with PHP, several ways to do the same thing.

You don't really need a MySQL database ... a simpler text file might be all you need.

The main issue lies with how your client edits/adds/deletes the various photos, text,
and schedule. Most of the PHP programming will go into the admin part, so they can
edit things online with some sort of simple password.

So, the complexity depends on how much interaction and administration is needed,
how much the schedule changes, and how much control your client has over the script.

Displaying the thing on the web page itself can be done using PHP, or can be done
using Javascripting, if they don't want to mess with the .html page extension.
You'll need to either use .php (instead of .html), or command the server to execute
.html files as PHP scripts (using .htaccess). In your case, like a hit counter, the
"what's in bloom" thing could be a Javascript that uses a separate PHP script.

01-14-2010, 06:58 PM
Wow! so many responses so quickly!

OK, let me address some of the questions here.

First, server time is fine. The server is in the building where the greenhouse is. It's all part of a college, so "What's in Bloom" refers to the greenhouse itself and it's location which is the same as the server. The user's time zone does not matter.

It would be fine to create a text file that contains links to the image to display as well as a quote to place under the image. The text file could also display the time and date to display each image. The current image would continue to display until a new time and date is encountered.

Does any of that help as far as deciding how this should be programmed?

Thank you again for all your help!

Philip M
01-14-2010, 10:10 PM
JavaScript ought to be entirely adequate for this.

A simple example:-

<script type = "text/javascript">
Date.prototype.getDOY = function() {
var onejan = new Date(this.getFullYear(),0,1);
return Math.ceil((this - onejan) / 86400000);
var today = new Date();
var DOY = today.getDOY(); // DOY = Day Of Year 1 -366
if (DOY >= 14 && DOY <=35) {
document.getElementById("plantPicture").src = "Daisys.jpg";
document.getElementById("plantText").innerHTML = "plantDetails1";
if (DOY > 35) {
document.getElementById("plantPicture").src = "Fushias.jpg";
document.getElementById("plantText").innerHTML = "plantDetails2"

01-14-2010, 10:26 PM
That looks great!

I'm afraid I don't understand where to store the plantText.

Where is plantDetails1, etc. stored?