You are not logged in.

  • Login

1

Saturday, January 20th 2007, 2:38pm

Statusbalken in PHP

Hallo.
ich hab mal ne frage und zwar wie kann man eine art grafische ausgabe machen mit php ? Nehmen wir an ich hab 2 Ausgaben die man machen könnte

15 User von 100 Online
und diese ausgabe in einem Prozentualen Statusbalken ?
geht sowas, wenn ja wie


Danke für eventuelle Antworten...

2

Saturday, January 20th 2007, 3:32pm

naja, mit php und html eben nur statisch. (ganz einfach über CSS)

Mit Ajax könnte man es auch asynchron abgleichen und animieren.
Falls du ein bisschen AJAX kannst, kannst du dieses HowTo als Basis nehmen: Ajax Bild bei Aenderung nachladen

Aber mit reinem php gehts nicht.

3

Saturday, January 20th 2007, 3:46pm

Ja das ist ja klar aer ich wollte nur ne simplen balken haben der zwei farben hat und zwar einmal das gesamte und dann die die online sind könntest mir da mla nen beispiel machen wie sowas realisierbar währe ?

4

Saturday, January 20th 2007, 3:58pm

Quick & Dirty - Nur als Beispiel gedacht!

PHP Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
$maxwidth = 200;
$maxusers = 75;
$onlineusers = 70;
 
$percent = 100 / $maxusers * $onlineusers;
$loadwidth = $maxwidth - ($percent / 100) * $maxwidth;
 
$buffer = "
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">
<html>
<head>
<meta http-equiv=\"content-type\" content=\"text/html; charset=ISO-8859-1\">
 
<title>Speicherplatzbelegung</title>
 
<style type=\"text/css\">
 
.speicher {
background-color: green;
width: ".$maxwidth."px;
height: 15px;
overflow: hidden;
padding: 0;
}
 
.balken {
top: 0;
width: ".$maxwidth."px;
height: 15px;
background-color: red;
}
 
</style>
 
</head>
<body>
 
$onlineusers von $maxusers online!
<div class=\"speicher\">
<div class=\"balken\" style=\"position: relative; left: -".$loadwidth."px;\"></div>
</div>
 
</body>
</html>";
 
echo $buffer;
?>

5

Saturday, January 20th 2007, 3:59pm

Das geht wunderbar mit PHP, einzige Einschränkung: der Balken wird nur aktualisiert wenn die Seite neu geladen wird. Möchtest du das dynamisch immer machen brauchste wohl JavaScript.
Ich würde es mit PHP und GD machen und den Statusbalken als Grafik einbinden. GD ist eigentlich immer mit installiert.

6

Sunday, January 21st 2007, 3:14pm

Also ich probier mich damit nachher mal mal sehen was dabei rauskommt, also beim Seite laden aktualisieren reicht vollkommen ^^

7

Sunday, January 21st 2007, 3:59pm

Also wenn Du eine Prozentuale Berechnung hast, dann hilft Dir vielleicht das weiter:

imagefilledrectangle

Das nehme ich auch her. Mein Code:

ratingbar.php

PHP Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
 
// copied from the PHP manual:
// http://us3.php.net/manual/en/function.imagefilledrectangle.php
//this needs to reside in its own php page
//you can include that php page in your html as you would an image:
//<IMG SRC="makebar.php?rating=25.2&width=200&height=20" border="0">
// rating is a percentage from 0 to 100.
 
function drawRating($rating) {
   $width = $_GET['width'];
   $height = $_GET['height'];
   if ($width == 0) {
     $width = 300;
   }
   if ($height == 0) {
     $height = 15;
   }
 
   $rating = $_GET['rating'];
   $ratingbar = (($rating/100)*$width)-2;
 
   $image = imagecreate($width,$height);
   //colors
 
   $fill = ImageColorAllocate($image,0,255,0); //grün
   if ($rating > 49) { $fill = ImageColorAllocate($image,255,255,0); } //gelb
   if ($rating > 74) { $fill = ImageColorAllocate($image,255,128,0); } //orange
   if ($rating > 89) { $fill = ImageColorAllocate($image,255,0,0); } //rot
 
   $back = ImageColorAllocate($image,255,255,255);
   $border = ImageColorAllocate($image,0,0,0);
 
   ImageFilledRectangle($image,0,0,$width-1,$height-1,$back);
   ImageFilledRectangle($image,1,1,$ratingbar,$height-1,$fill);
   ImageRectangle($image,0,0,$width-1,$height-1,$border);
   imagePNG($image);
   imagedestroy($image);
}
 
Header("Content-type: image/png");
drawRating($rating);
 
?>


Und so lasse ich mir z. B. meinen freien Festplattenplatz anzeigen:

PHP Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?
function ZahlenFormatieren($Wert)
{
    if($Wert > 1099511627776)
    {
        $Wert = number_format($Wert/1099511627776, 2, ",", ".")." TB";
    }
    elseif($Wert > 1073741824)
    {
        $Wert = number_format($Wert/1073741824, 2, ",", ".")." GB";
    }
    elseif($Wert > 1048576)
    {
        $Wert = number_format($Wert/1048576, 2, ",", ".")." MB";
    }
    elseif($Wert > 1024)
    {
        $Wert = number_format($Wert/1024, 2, ",", ".")." kB";
    }
    else
    {
        $Wert = number_format($Wert, 2, ",", ".")." Bytes";
    }
 
    return $Wert;
}
 
$frei = disk_free_space("./");
$insgesamt = disk_total_space("./");
$belegt = $insgesamt-$frei;
$prozent_belegt = 100*$belegt/$insgesamt;
?>
</td><td>
<table width=340 border=0 cellspacing=1 cellpadding=3 bgcolor=#C0C0C0>
<tr><td bgcolor=#F4F4F4><? echo $lang[diskspace];?></td><td bgcolor=#F4F4F4><?=ZahlenFormatieren($insgesamt);?></td></tr>
<tr><td bgcolor=#F4F4F4><? echo $lang[in_use];?></td><td bgcolor=#F4F4F4><?=ZahlenFormatieren($belegt);?>    (<?=round($prozent_belegt,"2");?> %)</td></tr>
<tr><td colspan=2 bgcolor=#F4F4F4 align=center><center><img src="ratingbar.php?rating=<?=round($prozent_belegt,"2");?>" border="0"></td></tr>
<tr><td bgcolor=#F4F4F4><? echo $lang[free];?></td><td bgcolor=#F4F4F4><?=ZahlenFormatieren($frei);?>
</td></tr></table>


Gruß Inekai

8

Sunday, January 21st 2007, 10:48pm

Also die ratingbar ist net schlecht aber ich musste die noch stark erweitern....
danke erstma

10

Wednesday, February 21st 2007, 4:58pm

^__^

Similar threads

Social bookmarks