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
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 : countdown - The script was created to count how many days were remaining for an event in the same year.
Categories : PHP Update Picture
Chris Sano
Date : Jul 08th 2001
Grade : 5 of 5 (graded 1 times)
Viewed : 2047
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Chris Sano
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

<?
/*
___________________________________________________________________________
____
countdown v0.2

created: 04.15.2001
updated: 07.09.2001
___________________________________________________________________________
____
-:[ script history ]:-

04.15.2001        .
                        
07.09.2001        Updated script so that count down was possible for an event in a
                        different year.
___________________________________________________________________________
____
-:[ script summary ]:-

Count down to a special event with this script. Enter the date in MM.DD.YYYY
format when instantiating the class and call the displayCountdown method
wherever you want the countdown to be displayed.

It is recommended that you include this file in another PHP document and create
an instance to the countdown class in there. This can be done by doing
something similar to this:

include( "directory/to/this/file/countdown.php" );
$count = new countdown( "11.06.2001" );
echo $count->displayCountdown() . " days until my birthday.";
___________________________________________________________________________
____

©2001 chris sano [sano@mail.rit.edu]
I'm open for any feedback on how this script can be improved.

Visit my website at http://sanographics.com
___________________________________________________________________________
____
*/

class countdown {

        // initialize
        function countdown( $event_date ){
                
                // set the default number of days remaining until the desired date.
                $num_days_left = 0;
                // split the date that is passed through the class instantiation using
                // the period delimiter.
                $split_event_date = explode( ".", $event_date );
                // get current month in digital format.
                $current_month = date( "m" );
                
                // loop through the years
                for ( $year = date( "Y" ); $year <= $split_event_date[ 2 ]; $year++ ) {
                
                        // if there is a difference in the year, the month needs to default
                        // to 12 so the number of days between today and december
31st can
                        // be calculated before calculating the days into the next year
(s).
                        if ( $split_event_date[ 2 ] > $year ) {
                                // set the end month to december.
                                $end_month = 12;
                        } else {
                                // set the end month to the date to the value the
user input.
                                $end_month = $split_event_date[ 0 ];
                        }

                        // loop through the months.
                        for ( $i = $current_month; ( ( $year != $split_event_date[
2 ] ) ? $i <= $end_month : $i < $end_month ); $i++ ){
                        
                                // find the maximum number of days in the current
month.
                                $max_days_in_month = date( "d", mktime( 0, 0, 0, (
$i + 1 ), 0, $year ) );
                                // add to total
                                $num_days_left += $max_days_in_month;
                        
                        }
                        // set current month to january.
                        $current_month = 1;

                }

                // do final calculations.
                $this->num_days_left = ( $num_days_left - date( "d" ) ) +
$split_event_date[ 1 ];
                // ensure that a negative number is not output.
                $this->num_days_left = $this->num_days_left >= 0 ? $this-
>num_days_left : 0;
        }
        
        function displayCountdown(){
                // output
                echo $this->num_days_left;
        }

}

?>



Query2Report : Generating Html, Pdf and Csv Reports from SQL Query
Categories : PHP, PHP, HTML, PDF, Excel
Accepts a database & hostname from a user and then HTTP username and password. Uses this to connect to a MySQL database. Produces a form based on the tables it finds there to allow the user to do SELECTs, INSERTs, and DELETEs.
Categories : Databases, PHP, MySQL, Complete Programs
PHP Script to find url links in a page
Categories : PHP, URLs, Regexps, Arrays
Using $PHP_AUTH_USER and $PHP_AUTH_PW to authenticate.
Categories : Authentication, PHP
very simple ftp class
Categories : PHP, PHP Classes, FTP
PHP Paypal IPN Integration Class v1.0.0
Categories : PHP, PHP Classes, Payment Gateways
Function to remember password
Categories : PHP, Authentication, Personalization and Membership
Create Thumbnails - resize an image - jpeg, jpg, gif, png to the specifed width and height in proportion without loosing out on pixcel quality.
Categories : PHP, GD image library, Graphics
readline -- Reads a line
Categories : PHP, PHP Functions, Readline
a function that builds an HTML select list from any mysql table.
Categories : PHP, MySQL, HTML and PHP
Math operations on big numbers
Categories : PHP, Math.
phpAds, a complete banner and ad management system with detailled tracking and stats.
Categories : MySQL, Complete Programs, Ecommerce, PHP, Databases
Point and Click Interface ala MS Access for creating SQL statements.
Categories : MySQL, Complete Programs, General SQL, PHP, Databases
Tag content retrieval from websites with preg_match
Categories : PHP, Regexps, Arrays, HTML and PHP
Zephyr: AJAX Based Framework for PHP5 Developers
Categories : PHP, AJAX, Frameworks, Java Script, Web Applications
 Fred Horman wrote :676
IT works but it has on problem. If the event has passed the num_days_left is not = 0. In other words the script it not capable of producing a negative value.