Newgrounds.com — Everything, By Everyone.

Checking login status…

USERNAME:

PASSWORD:

Logging in…

Logged in as:
.
Logging out…
Inbox My Account Log Out


Forum Topic: Php: Website Progress/percentages

(1,465 views • 18 replies)

This topic is 1 page long.

<< < > >>
None

Greeley

Reply To Post Reply & Quote

Posted at: 11/14/05 05:05 AM

Greeley NEUTRAL LEVEL 13

Sign-Up: 08/30/05

Posts: 1,207

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


None

Casualty

Reply To Post Reply & Quote

Posted at: 11/14/05 05:53 AM

Casualty LIGHT LEVEL 33

Sign-Up: 09/15/04

Posts: 6,795

Nice tutorial, long live PHP: Main!


None

blah569

Reply To Post Reply & Quote

Posted at: 11/14/05 06:26 PM

blah569 DARK LEVEL 15

Sign-Up: 01/18/05

Posts: 1,983

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


None

Greeley

Reply To Post Reply & Quote

Posted at: 11/14/05 06:59 PM

Greeley NEUTRAL LEVEL 13

Sign-Up: 08/30/05

Posts: 1,207

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


None

DFox

Reply To Post Reply & Quote

Posted at: 11/14/05 07:31 PM

DFox LIGHT LEVEL 30

Sign-Up: 08/09/03

Posts: 9,216

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


None

Greeley

Reply To Post Reply & Quote

Posted at: 11/14/05 09:53 PM

Greeley NEUTRAL LEVEL 13

Sign-Up: 08/30/05

Posts: 1,207

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.


Happy

Zendra

Reply To Post Reply & Quote

Posted at: 12/1/05 03:48 AM

Zendra NEUTRAL LEVEL 37

Sign-Up: 09/07/03

Posts: 11,979

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

NG Review & BBS Moderator // PM Review & BBS Abuse


None

IWantSomeCookies

Reply To Post Reply & Quote

Posted at: 12/1/05 12:24 PM

IWantSomeCookies LIGHT LEVEL 13

Sign-Up: 08/20/04

Posts: 3,291

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

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


None

Greeley

Reply To Post Reply & Quote

Posted at: 12/14/05 12:15 AM

Greeley NEUTRAL LEVEL 13

Sign-Up: 08/30/05

Posts: 1,207

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.


None

EviLDoG

Reply To Post Reply & Quote

Posted at: 12/14/05 08:05 AM

EviLDoG FAB LEVEL 12

Sign-Up: 10/18/00

Posts: 4,127

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!


None

Greeley

Reply To Post Reply & Quote

Posted at: 12/14/05 03:12 PM

Greeley NEUTRAL LEVEL 13

Sign-Up: 08/30/05

Posts: 1,207

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


None

EviLDoG

Reply To Post Reply & Quote

Posted at: 12/14/05 03:24 PM

EviLDoG FAB LEVEL 12

Sign-Up: 10/18/00

Posts: 4,127

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!


None

Greeley

Reply To Post Reply & Quote

Posted at: 12/14/05 08:08 PM

Greeley NEUTRAL LEVEL 13

Sign-Up: 08/30/05

Posts: 1,207

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.


None

EviLDoG

Reply To Post Reply & Quote

Posted at: 12/15/05 09:04 AM

EviLDoG FAB LEVEL 12

Sign-Up: 10/18/00

Posts: 4,127

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.


None

Greeley

Reply To Post Reply & Quote

Posted at: 12/24/05 04:24 PM

Greeley NEUTRAL LEVEL 13

Sign-Up: 08/30/05

Posts: 1,207

OOOOhhh... kk yeah I get it now!


None

onnet5

Reply To Post Reply & Quote

Posted at: 2/27/06 12:52 PM

onnet5 NEUTRAL LEVEL 02

Sign-Up: 09/20/05

Posts: 37

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>


Happy

WoogieNoogie

Reply To Post Reply & Quote

Posted at: 2/27/06 06:25 PM

WoogieNoogie LIGHT LEVEL 14

Sign-Up: 06/26/05

Posts: 3,148

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;


Sleeping

ShinyChrome

Reply To Post Reply & Quote

Posted at: 9/30/07 03:42 PM

ShinyChrome LIGHT LEVEL 02

Sign-Up: 07/18/05

Posts: 7

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


None

different

Reply To Post Reply & Quote

Posted at: 10/1/07 04:53 AM

different DARK LEVEL 34

Sign-Up: 07/08/04

Posts: 3,753

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.

simple & minimal, that's my style.
thoughts on ux, usability & design


All times are Eastern Daylight Time (GMT -4) | Current Time: 04:35 PM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!