Here is a simple way to create a PHP based progress/status bar, which can also be used for ratings.
This uses the GD Graphical Library, so it must be installed on your webserver for it to function properly.
This PHP script draws a progress/status/ratings bar to the screen using an
tag in your HTML, which will be described below.
First, open your favorite PHP editor, create a file called "statusbar.php" and insert the following code.
Create an html page, something like statusbar.html and place the example tag below, into the HTML.
This will display the progress/status/ratings bar at 50/100.
You can modify the colors using RGB in the PHP code to change the colors of the progress bar.
This uses the GD Graphical Library, so it must be installed on your webserver for it to function properly.
This PHP script draws a progress/status/ratings bar to the screen using an
First, open your favorite PHP editor, create a file called "statusbar.php" and insert the following code.
Code :
// hide source code
// hide line numbers
// hide source code
// hide line numbers
1 <?php
2 function drawRating($rating) {
3 $width = isset($_GET['width']) ? $_GET['width'] : 50;
4 $height = isset($_GET['height']) ? $_GET['height'] : 10;
5 $ratingbar = (($rating/100)*$width)-2;
6 $image = imagecreate($width,$height);
7
8
9 //Change the colors here using RGB
10 $back = ImageColorAllocate($image,50,50,50);
11 $border = ImageColorAllocate($image,150,150,150);
12 $red = ImageColorAllocate($image,255,0,0);
13 $darkred = ImageColorAllocate($image,170,0,0);
14 $black = ImageColorAllocate($image,0,0,0);
15 $pipcolor = ImageColorAllocate($image,100,100,100);
16
17
18 $darkGreen = ImageColorAllocate($image,0,170,0);
19 $green = ImageColorAllocate($image,0,255,0);
20
21 ImageFilledRectangle($image,0,0,$width-1,$height-1,$back);
22 if($rating >= 50)
23 {
24 ImageFilledRectangle($image,1,1,$ratingbar,10,$darkGreen);
25 ImageFilledRectangle($image,1,1,$ratingbar,$height-4,$green);
26 }
27 else
28 {
29 ImageFilledRectangle($image,1,1,$ratingbar,10,$darkRed);
30 ImageFilledRectangle($image,1,1,$ratingbar,$height-4,$red);
31 }
32
33 //Sets PIP marks
34 for($i = 0; $i <= 5; $i++)
35 {
36 $pip = $i * 10;
37 ImageLine($image,$pip,1,$pip,10,$pipcolor);
38 }
39
40 ImageRectangle($image,0,0,$width-1,$height-1,$border);
41 imagePNG($image);
42 imagedestroy($image);
43
44
45 }
46 Header("Content-type: image/png");
47 drawRating($_REQUEST['rating']);
48 ?>
Create an html page, something like statusbar.html and place the example tag below, into the HTML.
Code :
// hide source code
// hide line numbers
// hide source code
// hide line numbers
1 <img src="/statusbar.php?rating=50" alt="Rated 50/100" />
This will display the progress/status/ratings bar at 50/100.
You can modify the colors using RGB in the PHP code to change the colors of the progress bar.
Donation:If you like our free quality work, make a donation by using Paypal and tell us what you would like to see improved on our site for the next few months. |
|
No comments yet













Page Info












