Changing between images based on date
So I have a website which has three spaces for pictures: Space A, Space B, and Space C.
In Space A, I have 20 images (Images A1-A20) which I would like to rotate daily.
In Space B, I have 20 images (Images B1-B20) which I would like to change every 13 days. In Space C, I have 20 images (Images C1-C20) which I would like to change every 20 days.Therefore, let's say for instance I wanted my site to start based on Jan 1, 2000.
Spaces A,B,&C would have the following images based on the date:
1/1 - A1,B1,C1
1/2 - A2,B1,C1
1/3 - A3,B1,C1
...
1/12 - A12,B1,C1
1/13 - A13,B1,C1
1/14 - A14,B2,C1
1/15 - A15,B2,C1
...
1/20 - A20,B2,C1
1/21 - A1,B2,C2
1/22 - A2,B2,C2
1/23 - A3,B2,C2
...
1/26 - A6,B2,C2
1/27 - A7,B3,C2
1/28 - A8,B3,C2
etc.
Therefore, I think I need a DateTime program that finds the number of elapsed days between the starting date (Jan 1, 2000), and the date listed on the computer, divides by the appropriate number (20,260,4开发者_JAVA技巧00), uses the remainder or fraction to determine which picture is appropriate and picks it to display, but haven't a clue how to write it / where to start.
Suggestions appreciated.
Thanks, NP
If you've been looking for a reason to learn php or perl or similar, this is it. If not, then try rent-a-coder or similar. There's a lot more to getting your first program working than just the code--you need to figure out how to get the software loaded and working correctly on your server.
The good news is that you seem to know your problem statement well. I'd go to a bookstore and look at the php or perl books until you see one that seems helpful, then go for it. And we here at SO stand ready to answer all questions from true seekers...
ps. For your problem, php would be a good starting bet if you're using a Linux web server.
Larry K is correct in that you have the problem pretty well defined and will need some sort of program to do this. PHP and Perl would be good choices, but there are ways in which you could do this with virtually any language: Python, C, Ruby, .... One technique would be to run a cron job (assuming Linux or another Unix variant) to re-write your HTML file every day (at midnight or thereabouts). Another would be to write a CGI script to determine the proper images when the page is requested. The PHP way (or Perl or Python if using mod_perl or mod_python) would embed (or pull in) the code directly in the web page and execute when the page is requested. I suggest you play around and pick what works best for you and your situation.
FWIW, if it were me, and I could do it any way I liked, I'd probably write a Python script to run as a cron job. Python just because that's currently my favorite language, and doing it by a cron job minimizes the processing required to do the job by doing it just once per day. However, some web hosting companies don't provide cron (or Python :-( ); if that were the case, I'd do it with PHP embedded in the web page, assuming I could use PHP (which seems ubiquitous with web hosting companies).
精彩评论