954,580 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How can you create Date controlled content?

I'm still very new to this but is there a way to control content (text and/or image) using PHP and a specific date? For example I need to add "New Store Hours" to a listing of locations for a client website, however I don't want to have to go back into all of the pages and turn them off after a few weeks. Any help or suggestions would be much appreciated.

Marty1963
Newbie Poster
15 posts since Jan 2011
Reputation Points: 10
Solved Threads: 0
 

USe a DB to store times and locations:

e.g.

stores
store_id (int/3/PK)
store_name (varchar/50)
store_address1 (varchar/100)
store_address1 (varchar/100)
store_address1 (varchar/100)
store_postcode (varchar/8)
store_www (varchar/50)
store_email (varchar/75)
store_tel1 (varchar/16)
active (tinyint/1) - this can decide whether the store is displayed or not
...(etc)...

times
store_id (int/3)
date_id (int/3)
day_no (0-6 = SUN-SAT)
opentime (24hour format)
closetime (24hour format)

(each store-date can have multiple entries e.g. AM opening, PM opening if req'd)

dates
date_id (int/3/PK)
datefrom (date)

This is a simplified relational model. Of course you could use a real date in the times table, but this may be wasteful.

Once you have the data in place, you then insert placeholders in your html for opening and closing times.

When you add new opening and closing times, if you query for the lastest date, then your data should be the most recent.

Hope that's the sort of thing you were looking for.

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

Thank you Ardav for your fast reply, however I was hoping to manage this without a database. Perhaps I was unclear, there are only one or two stores who change their hours at any given time. All I was after was a snippet of PHP code that would make a "New Hours" image or text not visable after a set period of time. Regards.

Marty1963
Newbie Poster
15 posts since Jan 2011
Reputation Points: 10
Solved Threads: 0
 

You could set a global variable and read from it. I think...

fpaquin
Newbie Poster
13 posts since Jan 2007
Reputation Points: 10
Solved Threads: 1
 

DOh! MY apologies - sometimes I read what I want to read - and totally get the wrong end of the stick.

Set a $timeoff variable (date for image to be taken off at the top of the page.

Then compare this against the current time. If ok, show image, if expired don't show it:

$timeoff = '2012-10-09 00:00:00';
$timenow = date('Y-m-d H:i:s');
$showimg = ($timenow >= $timeoff) ? false : true;


Then by your image:

<?php
if($showimg)echo '<img src="images/newtimes.png" title="Check out our new times!" />';
?>
diafol
Rhod Gilbert Fan (ardav)
Moderator
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

Fantastic!! Thank you that was just what I was looking for. I was able to write something that worked, but yours is much cleaner. I really appreciate your help.

Marty1963
Newbie Poster
15 posts since Jan 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: