|
|
|
Example updated according to the comment by Shiraz Esat
This code basically changes the background color of your webpage
depending on the time. It will change every ten minutes.
All you need to do is add the following code into your HTML document.
Simple!!!
Put this code in "colourchange.php"
| <?php
if(date("i") >= "00" && date("i") <= "09"){
$BGColour = "#CCCCCC";
}elseif(date("i") >= "10" && date("i") <= "19"){
$BGColour = "#A6CAF0";
}elseif(date("i") >= "20" && date("i") <= "29"){
$BGColour = "#E79703";
}elseif(date("i") >= "30" && date("i") <= "39"){
$BGColour = "#AE9675";
}elseif(date("i") >= "40" && date("i") <= "49"){
$BGColour = "#CFDDF4";
}elseif(date("i") >= "50" && date("i") <= "59"){
$BGColour = "#CCCCCC";
}
//Usage
//=====
<BODY BGCOLOR='<?php require("colourchange.php");print "$BGColour"); ?>'>
?> | | |
|
| Select with current month Categories : PHP, HTML and PHP, Date Time, Arrays | | | Creates three SELECT form fields: Month, Day, and Year. You give it a string which will be used to make the name for the three fields, and a number of seconds to use as the default date. If you give it blank for this value, the current date is used. Categories : HTML and PHP, PHP, Date Time | | | If you want to create select buttons featuring current date this example will show you how... Categories : Date Time, HTML and PHP, PHP | | | CALENDAR - easy calendar-navigation with PHP Categories : PHP, Date Time, HTML and PHP, Calendar | | | This script contains 2 functions: 1 to create html select object based on your own customer date format entry- "M d Y h:i.... etc". The second function processes the select object on submit back to unix time. Categories : PHP, Calendar, Date Time, HTML and PHP | | | Kewl Date Example Categories : PHP, HTML and PHP, Date Time, CSS, Beginner Guides | | | Simple PHP control CSS Calender Categories : PHP, HTML and PHP, Calendar, Date Time, CSS | | | Convert date's in YYYY-MM-DD (i.e. mysql format) into PHP3 timestamps. Also Find the difference in days between two PHP3 timestamps. Categories : HTML and PHP, PHP, MySQL, Date Time | | | Customizable Calendar Class Categories : HTML and PHP, Date Time, PHP, PHP Classes, Calendar | | | Local-to-user date and time display regardless of time zone or where the website's server is located Categories : PHP, Date Time, HTML and PHP, Java Script | | | PHP3: Formmail. Just a cgi formmail, but than in PHP. It is easy to use! Categories : HTML and PHP, Email, PHP, Perl, HTML and PHP | | | Future Date - Quick, easy addition of future date fields to HTML code using PHP. Categories : PHP, HTML and PHP, Date Time | | | Calendar using Date function Categories : HTML and PHP, PHP, Date Time, Calendar | | | a function that builds an HTML select list from any mysql table. Categories : PHP, MySQL, HTML and PHP | | | Tag content retrieval from websites with preg_match Categories : PHP, Regexps, Arrays, HTML and PHP | |
| | | | Shiraz Esat wrote : 1106
Good idea - pity the logic is flawed, and you haven`t explained how to use it with a clear example.
Logic Flaw:
if(date("i") >= "00"){
$BGColour = "#CCCCCC";
}elseif(date("i") >= "10"){
$BGColour = "#A6CAF0";
}....
Basically, $BGColour will always be "#CCCCCC". You need to change the if, elseif order:
if(date("i") >= "50"){
$BGColour = "#CCCCCC";
}elseif(date("i") >= "40"){
$BGColour = "#A6CAF0";
}....
To use:
<BODY BGCOLOR=`<?php require("colourchange.php");print "$BGColour"); ?>`>
(don`t forget the colourchange.php file)
| | | | Peter Warnock wrote : 1107
A more progessive application would be to include this in a style tag since html attributes are being depracated as we advance towards xhtml.
<html>
<head>
<style type="text/css">
<!--
body {
background-color: <?php echo $BGColour; ?>;
}
-->
</style>
</head>
<body>
</body>
</html>
or
<body style="background-color: <?php echo $BGColour; ?>;">
| | | | P C wrote :1108
You have an excellent idea. Your code, however, is hardcoded to change colors every 10 minutes.
If you would code the colours in an array, and use the mod function to determine which colour to use at what time (minutes, hours, day of the week, even months), then you could use the time interval as a user-definable parameter and give more possibilities.
To further the cause, if you want, you could even do interpolation between the two colours within the time interval so that the change would be a gradual one, if the user so desires.
The use of CSS, as suggested in a previous comment, would be a very wise choice in my opinion.
Thank you for contributing an excellent idea, and please keep up the good work.
| |
|
|
|