WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Website colour changer
Categories : PHP, HTML and PHP, Date Time Update Picture
James Dunn
Date : May 20th 2004
Grade : 2 of 5 (graded 5 times)
Viewed : 4723
File : No file for this code example.
Images : No Images for this code example.
Search : More code by James Dunn
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 


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") &gt;= "00"){ 
        $BGColour = "#CCCCCC"; 
    }elseif(date("i") &gt;= "10"){ 
        $BGColour = "#A6CAF0"; 
    }....

Basically, $BGColour will always be "#CCCCCC". You need to change the if, elseif order:

    if(date("i") &gt;= "50"){ 
        $BGColour = "#CCCCCC"; 
    }elseif(date("i") &gt;= "40"){ 
        $BGColour = "#A6CAF0"; 
    }....


To use:
&lt;BODY BGCOLOR=`&lt;?php require("colourchange.php");print "$BGColour"); ?&gt;`&gt;

(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.

&lt;html&gt;
  &lt;head&gt;
    &lt;style type="text/css"&gt;
     &lt;!--
       body {
    background-color: &lt;?php echo $BGColour; ?&gt;;
     }
     --&gt;
    &lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;/body&gt;
&lt;/html&gt;

or 

&lt;body style="background-color: &lt;?php echo $BGColour; ?&gt;;"&gt;
 
 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.