automating updates by date.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
basil
Forum Newbie
Posts: 4
Joined: Tue Mar 04, 2003 10:51 am

automating updates by date.

Post by basil »

I am new to php programming. Can anyone advise how to have my monthly newsletter and quiz update automatically on my website as the date changes each month. Is that simply an "if" "else" situation by having the date validate T/F or is there a function for this. Can't seem to find info or tutorials.
Thanks
Basil
redJag
Forum Newbie
Posts: 18
Joined: Fri Jan 31, 2003 12:17 am

Post by redJag »

If the files containing your newsletter and quiz can easily be named by date it would be pretty simple. Just get the current date and display the files that have that date in their name.
basil
Forum Newbie
Posts: 4
Joined: Tue Mar 04, 2003 10:51 am

Post by basil »

Have to think about that. I need 1 newsletter/quiz per month so not sure file name would work. Was thinking of making a variable from a date range IE >=mar1/03 and <=Mar31/03...then checking the current date and if true echo the file. Just not sure if that will work, and if so...not sure how to do it...
Thanks for your reply
Glenn
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

In rough outline, and assuming you've got all the content stored in a database, add a publication date column for each content row.

One way to do this would be to make a tinyint(2) column where you store 01, 02, 03 etc depending on the month you want to publish the item.

In the script which draws the page, get the current month with:

$current_month = date("m", time()); // eg gives 03 for March

..and then

SELECT whatever, cols, you, need FROM the_content_table WHERE publication_date='$current_month'
basil
Forum Newbie
Posts: 4
Joined: Tue Mar 04, 2003 10:51 am

Post by basil »

Thanks for your reply. Will try to get my head around your suggestion. Can see it working for quiz but not sure if newsletter content and graphics etc. can be stored in a database...perhaps???

Will keep digging and learning.
Thanks again
Basil
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

I wouldn't put graphics in a database - although some people do. If some graphics change once a month, you could stick img src links to them in the database with a publication date as above.

Newsletter text can go in a database no problem - lots of sites do it.

I don't know how familiar you are with php - take a look at some web tutorials if you haven't worked with databases much.

Ypou could even try something ready-rolled like the postnuke CMS.
redJag
Forum Newbie
Posts: 18
Joined: Fri Jan 31, 2003 12:17 am

Post by redJag »

If you save your monthly newsletter and quiz into files labeled newsletter##-####.html where ##-#### = numerical month-4 digit year then you can just use find out what month-year it is when the page is loaded and use an include respective to the date.

Code: Select all

<?php
$month = date("m", time());
$year  = date("Y", time());

//HTML and PHP to appear before and around newsletter here

include("newsletter".$month."-".$year.".html"); //or whatever extension

//HTML and PHP between newsletter and quiz here

include("quiz".$month."-".$year.".php");

//HTML and PHP after newsletter and quiz here

?>
basil
Forum Newbie
Posts: 4
Joined: Tue Mar 04, 2003 10:51 am

Post by basil »

Thanks so much!...I'll try and make that work

Glenn
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Ah.. yes.. month/year would be better if you maintain old items in the database - otherwise you'd be printing last years' March/ etc articles as well as the current ones.
Post Reply