00:00
00:00
Newgrounds Background Image Theme

Boayne98 just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Php: Website Progress/percentages

3,653 Views | 17 Replies
New Topic Respond to this Topic

Php: Website Progress/percentages 2005-11-14 05:05:27


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

Response to Php: Website Progress/percentages 2005-11-14 05:53:47


Nice tutorial, long live PHP: Main!


BEER BEER BEER BEER BEER BEER BEER BEER BEER BEER BEER

BEER BEER BEER BEER BEER BEER BEER BEER BEER BEER BEER

BEER BEER BEER BEER BEER BEER BEER BEER BEER BEER BEER

BBS Signature

Response to Php: Website Progress/percentages 2005-11-14 18:26:59


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


BBS Signature

Response to Php: Website Progress/percentages 2005-11-14 18:59:22


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

Response to Php: Website Progress/percentages 2005-11-14 19:31:55


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

Response to Php: Website Progress/percentages 2005-11-14 21:53:10


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.

Response to Php: Website Progress/percentages 2005-12-01 12:24:56


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


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

-TomFulp

Response to Php: Website Progress/percentages 2005-12-14 00:15:11


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.

Response to Php: Website Progress/percentages 2005-12-14 08:05:41


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!

Response to Php: Website Progress/percentages 2005-12-14 15:12:11


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

Response to Php: Website Progress/percentages 2005-12-14 15:24:13


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!

Response to Php: Website Progress/percentages 2005-12-14 20:08:32


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.

Response to Php: Website Progress/percentages 2005-12-15 09:04:05


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.

Response to Php: Website Progress/percentages 2005-12-24 16:24:25


OOOOhhh... kk yeah I get it now!

Response to Php: Website Progress/percentages 2006-02-27 12:52:35


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>

Response to Php: Website Progress/percentages 2006-02-27 18:25:17


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;

Response to Php: Website Progress/percentages 2007-09-30 15:42:33


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

Response to Php: Website Progress/percentages 2007-10-01 04:53:01


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.