WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search


Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
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 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



Go Back Add a Comment Send this Article 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 SUBMIT AN ARTICLE PRINT
Title : Counting - Creating a GIF based counter using PHP and MySQL
Categories : Beginner Guides, PHP, To PHP, To MySQL, MySQL Picture not available
ScriptMakers.com
Date : 2000-02-27
Grade : 1 of 5 (graded 1 times)
Viewed : 16178
Search : More Articles by ScriptMakers.com
Action : Grade This Article
Tools : My Favotite Articles


Submit your own code examples 
 


Using the script we previously made (more specifically, we need the variable $count), we can now begin to create a graphical counter.

Note: This version does not require the GD library

On this page we'll make an HTML graphical counter. This means that image tags (<img>) will be dynamically added to the HTML, instead of an image being created dynamically. While this way of creating a counter is faster and lighter
on the system, all the pages with the counter must be PHP enabled.

This script can be used with any counter script. In this script, we are simply creating the image tags, not adding or updating the count values. If you use a different counter, just make sure to set the variable $count to the count value. In this tutorial, we'll use the script from the previous lesson. Let's get started...

First of all, you need to upload some digits to your website. A huge selection can be found at Digit Mania. Make sure that all these images have the same height and width.

Now it's time to set some variables:
->$path is the path to the images directory (ex /home/www/counter/images/)
->$url should be the HTTP path to that same directory (ex
http://www.domain.com/counter/images/).
->$ending is the file name of the images (normally '.gif')
->$default_style is the style if none is chosen (styles are explained below)

I thought it would be neat to be able to have multiple counter styles. For example, maybe I want to have a set of black digits as well as white digits. To do this, simply upload 0black.gif, 1black.gif, 2black.gif... 0white.gif,
1white.gif, 2white.gif, etc to the '/images/' directory. Then, if you want the digits to be black unless specified otherwise, make $default_style equal to 'black'. It's that easy!


<?
$path
= '/home/www/counter/images/';

$url = 'http://www.somedomain.com/counter/images';

$ending = '.gif';

$default_style = 'black';
?>


Now that we've set the initial variables, it's time to start the real coding. We need to check and see if the variable $style has been set. If it hasn't, then $style should be set equal to the $default_style. A simple trinary operator will suffice.



When that is completed, we can start to build the HTML. We need to get the height and width of the images that we'll be using. Because the height and width of all the images are the same, we only need to get the information once.

Note: The height and width of different styles can be different, just not any images of the same style.

PHP has a very handy function called GetImageSize() which suits our purposes perfectly. This function will actually print out the height and width HTML code!




<?
$path
= '/home/www/counter/images/';

$url = 'http://www.somedomain.com/counter/images';

$ending = '.gif';

$default_style = 'black';

$style = ($style)?$style:$default_style;

$size = GetImageSize($path. '1'.$style.$ending);
?>


Now it's time to print out the HTML. All we need to do is to loop through each number in $count, printing out the code as we go. That's all that's to it!


<?
$path
= '/home/www/counter/images/';

$url = 'http://www.somedomain.com/counter/images';

$ending = '.gif';

$default_style = 'black';

$style = ($style)?$style:$default_style;

$size = GetImageSize($path. '1'.$style.$ending);

for (
$i = 0; $i < strlen($count); $i++) {
echo
"<img src=\"$url$count[$i]$style$ending\" $size[3]>";
}
?>












Counting - Creating a more sophisticated GIF based counter using PHP and MySQL
Categories : Beginner Guides, MySQL, PHP, To PHP, To MySQL
Beginners guide to PHP and MySQL - Creating a simple guest book
Categories : Beginner Guides, To PHP, To MySQL, PHP, MySQL
Counting - Creating a simple counter
Categories : PHP, MySQL, Beginner Guides, To PHP, To MySQL
Jump Start to Easy URLs
Categories : PHP, Beginner Guides, MySQL, File System, To PHP
How TO Install PHP, Apache and MySQL on Linux or Unix
Categories : PHP, MySQL, Apache, Installation, Beginner Guides
Beginners guide to PHP and MySQL
Categories : PHP, Beginner Guides, Databases, MySQL, Installation
Who's Linking?
Categories : PHP, Beginner Guides, To PHP
Grabb'n and Pars'n
Categories : Beginner Guides, PHP, To PHP
Start Using MySQL
Categories : MySQL, Databases, To MySQL, Beginner Guides
How To add paging (Pagination) with PHP and MySQL
Categories : PHP, Beginner Guides, Databases, MySQL, HTML and PHP
Beginners Guide to PHP - Introduction to cookies
Categories : Beginner Guides, Cookies, To PHP, PHP
Creating an IE-Only Database Driven Menu System With PHP, MySQL and DHTML
Categories : PHP, MySQL, Databases, DHTML
PHP 101 Part 10 of 15 : A Session In The Cookie Jar
Categories : PHP, Beginner Guides, Cookies, Sessions
Case Study: Handling MySQL Growth With a PHP Class
Categories : Databases, MySQL, PHP
PHP, MySQL and Authentication 101
Categories : PHP, Databases, MySQL, Authentication