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.

Member Avatar for diafol

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.

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.

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

Member Avatar for diafol

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!" />';
?>

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.