Dynamisch PNG
Hallo allemaal,
Ik ben bezig met een grafiekje, hiervoor gebruik ik imagecreatetruecolor() om een PNG bestand te maken die de grafiek samenstelt.
Is het ook mogelijk om informatie uit de database te halen tijdens het samenstellen van de grafiek?
Telkens als ik contact maak met de DB werkt het plaatje niet meer..
Heeft iemand een oplossing?
Groetjes sander
Ik ben bezig met een grafiekje, hiervoor gebruik ik imagecreatetruecolor() om een PNG bestand te maken die de grafiek samenstelt.
Is het ook mogelijk om informatie uit de database te halen tijdens het samenstellen van de grafiek?
Telkens als ik contact maak met de DB werkt het plaatje niet meer..
Heeft iemand een oplossing?
Groetjes sander
tuurlijk lukt dit.
Oplossing, maak eerst eens contact met je DB zonder er meer me te doen, dan zie je dat het wel werkt
Oplossing, maak eerst eens contact met je DB zonder er meer me te doen, dan zie je dat het wel werkt
Oke, dit lukt inderdaad, maar wanneer ik mysql_num_rows(); gebruik om de klommen te tellen werkt het niet meer, ongeacht waar het staat..
maak eerst je code, haal alles op... etc etc.
stop het in varibelen etc, dan set je je header header(Content-Type: image/png)
dan ga je alle functies voor het plaatje handeling af
voorbeeldje:
Met andere woorden zorg ervoor dat er GEEN output is naar je browser.
Als mysql_num_rows een fout geeft bijvoorbeeld, komt er een error, wat betekent output.
Wat ik zo in je verhaal hoor; is je query niet goed opgebouwd!
stop het in varibelen etc, dan set je je header header(Content-Type: image/png)
dan ga je alle functies voor het plaatje handeling af
voorbeeldje:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
<?php
if(mysql_connect('localhost', 'username', 'password')) {
if(mysql_select_db('database')) {
if($selectthings = mysql_query("SELECT * FROM table WHERE id >= 12 LIMIT 5")) {
// in array stoppen, mysql_fetch_assoc
header('Content-Type: image/png');
$image = imagepng('blabla.png');
imagedestroy($image);
}
}
}
?>
if(mysql_connect('localhost', 'username', 'password')) {
if(mysql_select_db('database')) {
if($selectthings = mysql_query("SELECT * FROM table WHERE id >= 12 LIMIT 5")) {
// in array stoppen, mysql_fetch_assoc
header('Content-Type: image/png');
$image = imagepng('blabla.png');
imagedestroy($image);
}
}
}
?>
Met andere woorden zorg ervoor dat er GEEN output is naar je browser.
Als mysql_num_rows een fout geeft bijvoorbeeld, komt er een error, wat betekent output.
Wat ik zo in je verhaal hoor; is je query niet goed opgebouwd!
Dit doe ik, maar er blijft dit probleem, ik weet zeker dat de query werkt .. ik gebruik deze ook op een andere pagina.
Hier is mijn code
Hier is mijn code
Code (php)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
if ( mysql_connect("localhost","username","password")
|| mysql_select_db("database") ) {
$tell = mysql_query("SELECT `idnum` FROM `uniek` WHERE `ip`='".$_SERVER['REMOTE_ADDR']."' LIMIT 1");
$numer = mysql_num_rows($tell);
}
$im = @imagecreatetruecolor(400, 200)
or die("Cannot Initialize new GD image stream");
$text_color = imagecolorallocate($im, 231, 160, 7);
$tekstkl = imagecolorallocate($im, 32, 65, 142);
$bgColor = imagecolorallocate($im, 236, 239, 246);
$tussenas = imagecolorallocate($im, 184, 187, 241);
$grafiek = imagecolorallocate($im, 255, 24, 0);
imagefill($im , 0,0 , $bgColor);
//tusenassem
imageline($im, 1, 30, 400, 30, $tussenas);
imageline($im, 1, 50, 400, 50, $tussenas);
imageline($im, 1, 70, 400, 70, $tussenas);
imageline($im, 1, 90, 400, 90, $tussenas);
imageline($im, 1, 110, 400, 110, $tussenas);
imageline($im, 1, 130, 400, 130, $tussenas);
imageline($im, 1, 150, 400, 150, $tussenas);
imageline($im, 1, 170, 400, 170, $tussenas);
imageline($im, 1, 190, 400, 190, $tussenas);
imageline($im, 10, 20, 10, 200, $tussenas);
imageline($im, 30, 20, 30, 200, $tussenas);
imageline($im, 50, 20, 50, 200, $tussenas);
imageline($im, 70, 20, 70, 200, $tussenas);
imageline($im, 90, 20, 90, 200, $tussenas);
imageline($im, 110, 20, 110, 200, $tussenas);
imageline($im, 130, 20, 130, 200, $tussenas);
imageline($im, 150, 20, 150, 200, $tussenas);
imageline($im, 170, 20, 170, 200, $tussenas);
imageline($im, 190, 20, 190, 200, $tussenas);
imageline($im, 210, 20, 210, 200, $tussenas);
imageline($im, 230, 1, 230, 200, $tussenas);
imageline($im, 250, 1, 250, 200, $tussenas);
imageline($im, 270, 1, 270, 200, $tussenas);
imageline($im, 290, 1, 290, 200, $tussenas);
imageline($im, 310, 1, 310, 200, $tussenas);
imageline($im, 330, 1, 330, 200, $tussenas);
imageline($im, 350, 1, 350, 200, $tussenas);
imageline($im, 370, 1, 370, 200, $tussenas);
imageline($im, 390, 1, 390, 200, $tussenas);
//Assen horizontaal
imageline($im, 1, 1, 400, 1, $tekstkl);
imageline($im, 1, 20, 400, 20, $tekstkl);
imageline($im, 1, 40, 400, 40, $tekstkl);
imageline($im, 1, 60, 400, 60, $tekstkl);
imageline($im, 1, 80, 400, 80, $tekstkl);
imageline($im, 1, 100, 400, 100, $tekstkl);
imageline($im, 1, 120, 400, 120, $tekstkl);
imageline($im, 1, 140, 400, 140, $tekstkl);
imageline($im, 1, 160, 400, 160, $tekstkl);
imageline($im, 1, 180, 400, 180, $tekstkl);
//Assen verticaal
imageline($im, 20, 20, 20, 200, $tekstkl);
imageline($im, 40, 20, 40, 200, $tekstkl);
imageline($im, 60, 20, 60, 200, $tekstkl);
imageline($im, 80, 20, 80, 200, $tekstkl);
imageline($im, 100, 20, 100, 200, $tekstkl);
imageline($im, 120, 20, 120, 200, $tekstkl);
imageline($im, 140, 20, 140, 200, $tekstkl);
imageline($im, 160, 20, 160, 200, $tekstkl);
imageline($im, 160, 20, 160, 200, $tekstkl);
imageline($im, 180, 20, 180, 200, $tekstkl);
imageline($im, 200, 20, 200, 200, $tekstkl);
imageline($im, 220, 20, 220, 200, $tekstkl);
imageline($im, 240, 1, 240, 200, $tekstkl);
imageline($im, 260, 1, 260, 200, $tekstkl);
imageline($im, 280, 1, 280, 200, $tekstkl);
imageline($im, 300, 1, 300, 200, $tekstkl);
imageline($im, 320, 1, 320, 200, $tekstkl);
imageline($im, 340, 1, 340, 200, $tekstkl);
imageline($im, 360, 1, 360, 200, $tekstkl);
imageline($im, 380, 1, 380, 200, $tekstkl);
imagestring($im, 4, 5, 5, "$numer", $text_color);
if($total) { $total = $total * 4; $total = 180 - $total; } else { $total = 180; }
$time = strtotime ("now");
$vandaag = date("d", $time);
$tot = $total * 4;
imageline($im, 200, 180, 220, $total, $grafiek);
header ("Content-type: image/png");
imagepng($im);
imagedestroy($im);
?>
if ( mysql_connect("localhost","username","password")
|| mysql_select_db("database") ) {
$tell = mysql_query("SELECT `idnum` FROM `uniek` WHERE `ip`='".$_SERVER['REMOTE_ADDR']."' LIMIT 1");
$numer = mysql_num_rows($tell);
}
$im = @imagecreatetruecolor(400, 200)
or die("Cannot Initialize new GD image stream");
$text_color = imagecolorallocate($im, 231, 160, 7);
$tekstkl = imagecolorallocate($im, 32, 65, 142);
$bgColor = imagecolorallocate($im, 236, 239, 246);
$tussenas = imagecolorallocate($im, 184, 187, 241);
$grafiek = imagecolorallocate($im, 255, 24, 0);
imagefill($im , 0,0 , $bgColor);
//tusenassem
imageline($im, 1, 30, 400, 30, $tussenas);
imageline($im, 1, 50, 400, 50, $tussenas);
imageline($im, 1, 70, 400, 70, $tussenas);
imageline($im, 1, 90, 400, 90, $tussenas);
imageline($im, 1, 110, 400, 110, $tussenas);
imageline($im, 1, 130, 400, 130, $tussenas);
imageline($im, 1, 150, 400, 150, $tussenas);
imageline($im, 1, 170, 400, 170, $tussenas);
imageline($im, 1, 190, 400, 190, $tussenas);
imageline($im, 10, 20, 10, 200, $tussenas);
imageline($im, 30, 20, 30, 200, $tussenas);
imageline($im, 50, 20, 50, 200, $tussenas);
imageline($im, 70, 20, 70, 200, $tussenas);
imageline($im, 90, 20, 90, 200, $tussenas);
imageline($im, 110, 20, 110, 200, $tussenas);
imageline($im, 130, 20, 130, 200, $tussenas);
imageline($im, 150, 20, 150, 200, $tussenas);
imageline($im, 170, 20, 170, 200, $tussenas);
imageline($im, 190, 20, 190, 200, $tussenas);
imageline($im, 210, 20, 210, 200, $tussenas);
imageline($im, 230, 1, 230, 200, $tussenas);
imageline($im, 250, 1, 250, 200, $tussenas);
imageline($im, 270, 1, 270, 200, $tussenas);
imageline($im, 290, 1, 290, 200, $tussenas);
imageline($im, 310, 1, 310, 200, $tussenas);
imageline($im, 330, 1, 330, 200, $tussenas);
imageline($im, 350, 1, 350, 200, $tussenas);
imageline($im, 370, 1, 370, 200, $tussenas);
imageline($im, 390, 1, 390, 200, $tussenas);
//Assen horizontaal
imageline($im, 1, 1, 400, 1, $tekstkl);
imageline($im, 1, 20, 400, 20, $tekstkl);
imageline($im, 1, 40, 400, 40, $tekstkl);
imageline($im, 1, 60, 400, 60, $tekstkl);
imageline($im, 1, 80, 400, 80, $tekstkl);
imageline($im, 1, 100, 400, 100, $tekstkl);
imageline($im, 1, 120, 400, 120, $tekstkl);
imageline($im, 1, 140, 400, 140, $tekstkl);
imageline($im, 1, 160, 400, 160, $tekstkl);
imageline($im, 1, 180, 400, 180, $tekstkl);
//Assen verticaal
imageline($im, 20, 20, 20, 200, $tekstkl);
imageline($im, 40, 20, 40, 200, $tekstkl);
imageline($im, 60, 20, 60, 200, $tekstkl);
imageline($im, 80, 20, 80, 200, $tekstkl);
imageline($im, 100, 20, 100, 200, $tekstkl);
imageline($im, 120, 20, 120, 200, $tekstkl);
imageline($im, 140, 20, 140, 200, $tekstkl);
imageline($im, 160, 20, 160, 200, $tekstkl);
imageline($im, 160, 20, 160, 200, $tekstkl);
imageline($im, 180, 20, 180, 200, $tekstkl);
imageline($im, 200, 20, 200, 200, $tekstkl);
imageline($im, 220, 20, 220, 200, $tekstkl);
imageline($im, 240, 1, 240, 200, $tekstkl);
imageline($im, 260, 1, 260, 200, $tekstkl);
imageline($im, 280, 1, 280, 200, $tekstkl);
imageline($im, 300, 1, 300, 200, $tekstkl);
imageline($im, 320, 1, 320, 200, $tekstkl);
imageline($im, 340, 1, 340, 200, $tekstkl);
imageline($im, 360, 1, 360, 200, $tekstkl);
imageline($im, 380, 1, 380, 200, $tekstkl);
imagestring($im, 4, 5, 5, "$numer", $text_color);
if($total) { $total = $total * 4; $total = 180 - $total; } else { $total = 180; }
$time = strtotime ("now");
$vandaag = date("d", $time);
$tot = $total * 4;
imageline($im, 200, 180, 220, $total, $grafiek);
header ("Content-type: image/png");
imagepng($im);
imagedestroy($im);
?>
Aha, jullie hadden toch gelijk:)
Op mijn manier werkte de database selectie niet, daar kwam ik heel simpel achter door mysql_error() te gebruiken.
Dat had ik eerder moeten doen:P
Bedankt in ieder geval..
Op mijn manier werkte de database selectie niet, daar kwam ik heel simpel achter door mysql_error() te gebruiken.
Dat had ik eerder moeten doen:P
Bedankt in ieder geval..




