Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Jan 2010
    Location
    Quechee, VT
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Old dog needs new trick.

    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.

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    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.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    Quote Originally Posted by _Aerospace_Eng_ View Post
    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.

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Quote Originally Posted by kbluhm View Post
    ...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.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #5
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,472
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    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.

  • #6
    New to the CF scene
    Join Date
    Jan 2010
    Location
    Quechee, VT
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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!

  • #7
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,924
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    JavaScript ought to be entirely adequate for this.

    A simple example:-

    Code:
    <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"
    }

  • #8
    New to the CF scene
    Join Date
    Jan 2010
    Location
    Quechee, VT
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That looks great!

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


    Where is plantDetails1, etc. stored?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •