Be a Supporter!

Php: Website Progress/percentages

  • 2,292 Views
  • 18 Replies
New Topic Respond to this Topic
Greeley
Greeley
  • Member since: Aug. 30, 2005
  • Offline.
Forum Stats
Member
Level 13
Blank Slate
Php: Website Progress/percentages 2005-11-14 05:05:27 Reply

PHP: Main

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

Casualty
Casualty
  • Member since: Sep. 15, 2004
  • Offline.
Forum Stats
Member
Level 35
Musician
Response to Php: Website Progress/percentages 2005-11-14 05:53:47 Reply

Nice tutorial, long live PHP: Main!

blah569
blah569
  • Member since: Jan. 18, 2005
  • Offline.
Forum Stats
Member
Level 25
Programmer
Response to Php: Website Progress/percentages 2005-11-14 18:26:59 Reply

Nice! I might use this for one of my sites :).


BBS Signature
Greeley
Greeley
  • Member since: Aug. 30, 2005
  • Offline.
Forum Stats
Member
Level 13
Blank Slate
Response to Php: Website Progress/percentages 2005-11-14 18:59:22 Reply

Glad you guys like it. It is my first tutorial and I am basically a PHP Newby. I have a book that I've been reading and it helps alot. I figured this was something really simple so I decided why not post it. I could post other tutorials but I would need to refer to my book to make them. I made this all on my own and I happen to be proud of myself considering I've only been fluently doing PHP for about 2 weeks now, but I started reading about a month ago.

Thankyou for reading though :)

DFox
DFox
  • Member since: Aug. 9, 2003
  • Offline.
Forum Stats
Member
Level 30
Blank Slate
Response to Php: Website Progress/percentages 2005-11-14 19:31:55 Reply

VERY nice tutorial Greeley. Thanks for contributing to PHP: Main, and I hope to see some more tutorials!


BBS Signature
Greeley
Greeley
  • Member since: Aug. 30, 2005
  • Offline.
Forum Stats
Member
Level 13
Blank Slate
Response to Php: Website Progress/percentages 2005-11-14 21:53:10 Reply

At 11/14/05 07:31 PM, GamesCool wrote: VERY nice tutorial Greeley. Thanks for contributing to PHP: Main, and I hope to see some more tutorials!

I hope to make some more contributions the the PHP: Main thread. It probably won't be anything big for quite awhile yet. As I said, this is very basic because I only know and understand the basics. But I learn quick so hopefully I can get into some more complicated things soon.

Zendra
Zendra
  • Member since: Sep. 7, 2003
  • Offline.
Forum Stats
Moderator
Level 51
Blank Slate
Response to Php: Website Progress/percentages 2005-12-01 03:48:48 Reply

I guess it's quite simple, but since you're just getting started with PHP it's good to see you're understanding doing maths in PHP. :)
It's nice, little and it works. Good job, man! :)

IWantSomeCookies
IWantSomeCookies
  • Member since: Aug. 20, 2004
  • Offline.
Forum Stats
Member
Level 13
Blank Slate
Response to Php: Website Progress/percentages 2005-12-01 12:24:56 Reply

Such a simple script, yet explained so well. Good job..


"Actually, the server timed out trying to remove all your posts..."
-TomFulp

Greeley
Greeley
  • Member since: Aug. 30, 2005
  • Offline.
Forum Stats
Member
Level 13
Blank Slate
Response to Php: Website Progress/percentages 2005-12-14 00:15:11 Reply

Thankyou guys. I'm glad you like my simple script. I know it's simple but I see so many people not seeing that PHP can come in handy even in small situations like this. I also see people adding up precentages to get an overall and forgetting to divide by the number of precentages. Either that or they use a calculator. But glad you guys like it. I'm thinking of writing a user authentication tutorial soon. I will probably do it in parts but I will be basically just refering back to my code for this. Either that or I'll do something simple like getting data from a form.

EviLDoG
EviLDoG
  • Member since: Oct. 18, 2000
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to Php: Website Progress/percentages 2005-12-14 08:05:41 Reply

It's a good idea, sometimes you don't have to be good at coding (Not saying you aren't), but you can come up with great ideas instead.

like i came up with one i run on public PHP scripts (To alert the user if they don't have PHP installed):
<?php
/*
<script language="javascript">
alert ("You don't have PHP installed");
</script>
*/
# code down here
?>

You could easily make it redirect to the php website after the alert. It's just really for the beginners who just build websites and don't know a thing about coding.

The javascript gets parsed because if they don't have php installed it will show up (Which is what we want), if it is installed, the javascript is commented out, so no errors show! Simple but effective!

Greeley
Greeley
  • Member since: Aug. 30, 2005
  • Offline.
Forum Stats
Member
Level 13
Blank Slate
Response to Php: Website Progress/percentages 2005-12-14 15:12:11 Reply

How would this work if you didn't have php installed?

EviLDoG
EviLDoG
  • Member since: Oct. 18, 2000
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to Php: Website Progress/percentages 2005-12-14 15:24:13 Reply

At 12/14/05 03:12 PM, Greeley wrote: How would this work if you didn't have php installed?

<script language="javascript">
var layout = 90;
var membersystem = 4;
var cartoonportal = 0;
var gameportal = 0;
var comicportal = 0;
var forum = 0;
var adminfeatures = 0;
var overall = (layout+cartoonportal+gameportal+comicport
al+forum+adminfeatures)/7;
document.write ( 'Layout: ' + layout + '%<br />');
document.write ( 'Member System: ' + membersystem + '%<br />');
document.write ( 'Cartoon Portal: ' + cartoonportal + '%<br />');
document.write ( 'Game Portal: ' + gameportal + '%<br />');
document.write ( 'Comic Portal: ' + comicportal + '%<br />');
document.write ( 'Forums: ' + forum + '%<br />');
document.write ( 'Mod/Admin Features: ' + adminfeatures + '%');
document.write ( '<p>Overall Progress: ' + overall.toFixed(2) + '%</p>');
</script>

in javascript of course!

Greeley
Greeley
  • Member since: Aug. 30, 2005
  • Offline.
Forum Stats
Member
Level 13
Blank Slate
Response to Php: Website Progress/percentages 2005-12-14 20:08:32 Reply

At 12/14/05 03:24 PM, EviLDoG wrote: in javascript of course!

I was refering to your earlier post. Not what I did in my tutorial.

EviLDoG
EviLDoG
  • Member since: Oct. 18, 2000
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to Php: Website Progress/percentages 2005-12-15 09:04:05 Reply

At 12/14/05 08:08 PM, Greeley wrote:
At 12/14/05 03:24 PM, EviLDoG wrote: in javascript of course!
I was refering to your earlier post. Not what I did in my tutorial.

It don't make the script work if php isn't installed, it just means because php isn't installed, it will ignore the php tags and open up the page as a normal html page. So, it then displays the code as a html file basically and notifies the user that they don't have php installed on the platform they are using.

Greeley
Greeley
  • Member since: Aug. 30, 2005
  • Offline.
Forum Stats
Member
Level 13
Blank Slate
Response to Php: Website Progress/percentages 2005-12-24 16:24:25 Reply

OOOOhhh... kk yeah I get it now!

onnet5
onnet5
  • Member since: Sep. 20, 2005
  • Offline.
Forum Stats
Member
Level 02
Blank Slate
Response to Php: Website Progress/percentages 2006-02-27 12:52:35 Reply

Ok, i've been trying this code now, and i'm baffled. I'm getting errors.

Parse error: syntax error, unexpected T_ECHO in /home/onnet/public_html/Test.php on line 19

Code:

<html>
<head>
<title>Meh</title>
</head>
<body>
<?php
//Variables for percentages
$Layout = 0;
$Coding = 0;
$Slicing = 0;
$Design = 0;
$Forum = 0;

//Overall percentage
$Overall = ($Layout + $Coding + $Slicing + $Design + $Forum) /5

//Percentages getting viewed
echo 'Layout:'.$Layout.'%';
echo 'Coding:'.$Coding.'%';
echo 'Slicing:'.$Slicing.'%';
echo 'Design:'.$Design.'%';
echo 'Forum:'.$Forum.'%';
echo 'Overall:'.number_format($Overall,1).'%';

?>
</body>
</html>

WoogieNoogie
WoogieNoogie
  • Member since: Jun. 26, 2005
  • Offline.
Forum Stats
Member
Level 15
Programmer
Response to Php: Website Progress/percentages 2006-02-27 18:25:17 Reply

At 2/27/06 12:52 PM, onnet5 wrote: $Overall = ($Layout + $Coding + $Slicing + $Design + $Forum) /5

There's your problem. Just add a semicolon onto the end of that, like this.

$Overall = ($Layout + $Coding + $Slicing + $Design + $Forum) /5;

ShinyChrome
ShinyChrome
  • Member since: Jul. 18, 2005
  • Offline.
Forum Stats
Member
Level 02
Gamer
Response to Php: Website Progress/percentages 2007-09-30 15:42:33 Reply

It's just some simple maths...
I actually thought it would be something more advanced, still, I guess it can't be more dynamic... *sigh*

7 variables

total = ($+$+$+$+$+$+$=7$)

Summary = total/number of variables.

Nice idea though and I guess it's suppose to be basic. :)

different
different
  • Member since: Jul. 8, 2004
  • Offline.
Forum Stats
Member
Level 35
Blank Slate
Response to Php: Website Progress/percentages 2007-10-01 04:53:01 Reply

I would too, want a more dynamic solution. Using arrays you could achieve the same thing.

$progress = array("Layout" => 75, "Admin" => 4);
echo "<ul>\n";
foreach ($progress as $d => $p)
{
echo "<li>" . $d .": " . $p . "%</li>\n";
}
echo "</ul>\n";

Haha, just realised this is a very old topic, so I didn't finish this code off. However, that would be quite easy to do.


> twitter.