Website Progress with Percentages
*NOTE*You must already have a basic understanding of PHP to understand this tutorial. You should know how to work with variables and how to use the echo function with variables.
We've all seen it. We come across a website that isn't quite finished yet. On the front page of that website, they display some statistics that show approximately how close the site is to being done. When we see this it can be either accurate, or inaccurate. When accurate, it is done something like this.
Start by thinking about what you want the visitors to know. For my website I've decided I want the visitors to know the following:
-Layout Completion
-Member System Completion
-Cartoon Portal Completion
-Game Portal Completion
-Comic Portal Completion
-Forums Completion
-Mod/Admin Features Completion
-Overall Progress Completion
This is where things get a little innacurate. For each of the above (excluding overall progress which will be calculated in the php script) you have to guess the pecentage of completion. So I'm going to guess my layout is 75% done, my member system is 4% done, and everything else is 0% done. Here is the first bit of script:
$layout = 75;
$membersystem = 4;
$cartoonportal = 0;
$gameportal = 0;
$comicportal = 0;
$forum = 0;
$adminfeatures = 0;
The above script just sets the variables. Notice that I said my layout is 75 percent done, and my member system is 4% done; $layout =75 and $membersystem=4... Coincidence? I think not. Okay not let's progress onward into the calculating the overall progress. Use the following code to do so:
$overall = ($layout + $membersystem + $cartoonportal + $gameportal +
$comicportal + $forum + $adminfeatures) / 7;
In the above code you are creating a new variable for the overall progress of the site. That variable is equal to your other variables added together and then divided by seven. This isn't a math lesson so I'm only going to go over this briefly. The number you divide by is equal to the number of variables (excluding $overall). If you don't get it, then wait till they teach you it in math. Enough chitter chatter because it is time to display the code on the page by 'echo'ing it. Here is the code you'll need for that:
echo 'Layout: '.$layout.'%<br />';
echo 'Member System: '.$membersystem.'%<br />';
echo 'Cartoon Portal: '.$cartoonportal.'%<br />';
echo 'Game Portal: '.$gameportal.'%<br />';
echo 'Comic Portal: '.$comicportal.'%<br />';
echo 'Forums: '.$forum.'%<br />';
echo 'Mod/Admin Features: '.$adminfeatures.'%';
echo '<p>Overall Progress: '.number_format($overall,1).'%</p>';
The above code just simply displays the progresso n the site. Notice on the bottom line '.number_format($overall,1).'. The '1' specifies the number of decimals you want your overall progress variable to round to when it is being displayed. You can change it to any number to display the amount of decimal points you want it to.
Thankyou for joining me and reading my tutorial. Here is what the code should look like together:
<?php
// Set Variables to approximate completion percentages
$layout = 75;
$membersystem = 4;
$cartoonportal = 0;
$gameportal = 0;
$comicportal = 0;
$forum = 0;
$adminfeatures = 0;
// Do a math equation for calculating the overall progress
$overall = ($layout + $membersystem + $cartoonportal + $gameportal +
$comicportal + $forum + $adminfeatures) / 7;
// Display the statistics on your page for veiwers to veiw
echo 'Layout: '.$layout.'%<br />';
echo 'Member System: '.$membersystem.'%<br />';
echo 'Cartoon Portal: '.$cartoonportal.'%<br />';
echo 'Game Portal: '.$gameportal.'%<br />';
echo 'Comic Portal: '.$comicportal.'%<br />';
echo 'Forums: '.$forum.'%<br />';
echo 'Mod/Admin Features: '.$adminfeatures.'%';
echo '<p>Overall Progress: '.number_format($overall,1).'%</p>';
?>
If you have any questions post away. You can see an example of this at www.greeleyentertainment.com (aka.. my website).