Hallo,
Ik heb een script dat een grafiek aanmaakt in php.
Hiervoor gebruikt hij de mysql database als bron.
Het probleem is dat hij in Firefox (en Opera ook, internet explorer kan ik niet testen omdat ik op een Apple zit) de volgende melding krijg:
Dit is de php code:
Ik heb een script dat een grafiek aanmaakt in php.
Hiervoor gebruikt hij de mysql database als bron.
Het probleem is dat hij in Firefox (en Opera ook, internet explorer kan ik niet testen omdat ik op een Apple zit) de volgende melding krijg:
Als ik de error reporting van php op all zet dan krijg ik hetzelfde.De afbeelding “http://swimtrainer.uni.cc/system/grafieken/50_rugcrawl.php?startnummer=9204260” kan niet worden weergegeven, omdat hij fouten bevat.
Dit is de php 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
| <?php require("../config.php"); //$sql = mysql_query("SELECT * FROM zwemmers WHERE startnummer = $startnummer") or die ( mysql_error( ) ); while($record = mysql_fetch_object($sql)){ $gebruikersnaam = $record->naam; } $volledigenaam = $gebruikersnaam; $volledigenaam = str_replace(" "," ",$volledigenaam); $hoofdarray= array (); $r = 0; $sql1 = mysql_query("SELECT * FROM uitslagen WHERE startnummer='$startnummer' AND slag='rugcrawl' AND afstand='50' ORDER BY datum ASC") or die (mysql_error()); while ($var = mysql_fetch_object($sql1)) { $r++; $eindtijd = $var->eindtijd; // De code die hieronder gemarkeerd is is de orginele code. Eronder staat de nieuwe code. /* $Hhonderd = substr($eindtijd, -2); $Hseconde = substr($eindtijd, -5, 2); if(strlen($eindtijd) > 7) {$Hminuten = substr($eindtijd, 0 ,2);} else {$Hminuten = "0".substr($eindtijd, 0 ,1);} */ $data = $eindtijd; list($uur, $minuut, $seconde, $honderdste) = explode(":", ".", $data); $eindtijd = $minuut.$seconde.$honderdste; $datum = $var->datum.$r; addArray($hoofdarray, $eindtijd, $datum); } function addArray(&$array, $id, $var) { $tempArray = array($var => $id); $array = array_merge ($array, $tempArray); } $titel = "50m Rugcrawl [$volledigenaam]"; $lijnen = mysql_num_rows($sql1); $lijnen++; $gebied_breedte = 750; // grootte van de grafiek zelf (zonder randen) $gebied_hoogte = 300; // hoogte van de grafiek zelf (zonder randen) $rand_links = 80; // de breedte van de linker rand (hou rekening met de lengte van de waardes die op de y-as komen, in toekomst misschien automatisch) $rand_rechts = 60; // de breedte van de rechter rand $rand_onder = 120; // de rand onder de grafiek (hou rekening met de lengte van de waardes die op de x-as komen, in toekomst misschien automatisch) $rand_boven = 60; // de rand boven (hou rekening met de titel die hier in komt) $hor_lijnen = 10; // het aantal verdelingen van de y-as $hor_raster = TRUE; // horizontale lijnen zichtbaar? $ver_lijnen = $lijnen; // het aantal verdelingen van de x-as $ver_raster = TRUE; // verticale lijnen zichtbaar? $grafiek_titel = $titel; // de titel van de grafiek header("Content-type: image/png"); if(function_exists("ImageCreateTrueColor")) { $plaatje = ImageCreateTrueColor(($gebied_breedte + $rand_rechts + $rand_links), ($gebied_hoogte + $rand_onder + $rand_boven)); } else { $plaatje = ImageCreate(($gebied_breedte + $rand_rechts + $rand_links), ($gebied_hoogte + $rand_onder + $rand_boven)); } $zwart = ImageColorAllocate($plaatje, 000, 000, 000); $wit = ImageColorAllocate($plaatje, 255, 255, 255); $grijs = ImageColorAllocate($plaatje, 225, 225, 225); $lijn = ImageColorAllocate($plaatje, 135, 135, 185); // grijze grafieklijn $lijn2 = ImageColorAllocate($plaatje, 000, 000, 255); // blauwe grafieklijn imagefill($plaatje,1,1,$wit); imagefilledrectangle($plaatje, ($rand_links + 1), ($rand_boven + 1), ($rand_links + $gebied_breedte - 1), ($rand_boven + $gebied_hoogte -1), $grijs); $hoogste = 1; foreach($hoofdarray as $key => $value)if($value > $hoogste)$hoogste = $value; $style=array($zwart, $zwart, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT ); imagesetstyle($plaatje,$style); $waarde = 1; for($y = $rand_boven;$y < ($gebied_hoogte + $rand_boven + 1);$y += ($gebied_hoogte / $hor_lijnen)) { $notatie = round($hoogste * $waarde); $honderdste = substr($notatie, -2); $seconden = substr($notatie, -4, 2); if(strlen($notatie) == "6"){$minuten = substr($notatie, 0, 2);} if(strlen($notatie) == "5"){$minuten = "0".substr($notatie, 0, 1);} if(strlen($notatie) == "4"){$minuten = "00";} if($seconden > 59){$minuten = $minuten - -1;$seconden = $seconden -60;} if(strlen($minuten) < 1){$minuten = "0".$minuten;} if(strlen($seconden) < 1){$seconden = "0".$seconden;} if(strlen($honderdste) < 1){$honderdste = "0".$honderdste;} if(strlen($minuten) < 2){$minuten = "0".$minuten;} if(strlen($seconden) < 2){$seconden = "0".$seconden;} if(strlen($honderdste) < 2){$honderdste = "0".$honderdste;} $notatie = "$minuten:$seconden:$honderdste"; if($notatie == "01:00:0"){$notatie = "00:00:00";} $align = $rand_links - 9 - strlen($notatie) * 5; imagestring($plaatje, 2, $align, $y - 7 , $notatie, $zwart); if($hor_raster)imageline($plaatje, $rand_links, $y, ($rand_links + $gebied_breedte), $y, IMG_COLOR_STYLED); $waarde -= (1 / $hor_lijnen); } $aantal = count($hoofdarray); $interval = $gebied_breedte / ($aantal - 1); $yinterval = $gebied_hoogte / $hoogste; $x = $rand_links; $coords = array(); $ticker = 0; $numdates = round($aantal / $ver_lijnen); if($numdates < 1)$numdates = 1; foreach($hoofdarray as $xas => $yas) { $coords[$ticker]["x"] = round($x); $coords[$ticker]["y"] = ($rand_boven + $gebied_hoogte) - (round($yas * $yinterval)); $notatie2 = $yas; $Hhonderd = substr($notatie2, -2); $Hseconde = substr($notatie2, -4, 2); $Hminuten = substr($notatie2, 0 ,2); $notatie2 = "[".$Hminuten.":".$Hseconde.":".$Hhonderd."]"; if($ticker / $numdates == round($ticker / $numdates) || $ticker == 0 || $ticker == $aantal-1) { $notatie = substr($xas, 0, 10); $align = ($gebied_hoogte + $rand_boven) + (strlen($notatie) * 5) + 14; imagestringup($plaatje, 2 , round($x) - 4 , $align, $notatie ,$zwart); imagestringup($plaatje, 2 , round($x) + 6 , $align, $notatie2 ,$zwart); if($ver_raster)imageline($plaatje, round($x) , $rand_boven , round($x) , ($rand_boven + $gebied_hoogte), IMG_COLOR_STYLED); } $x += $interval; $ticker++; } for($a = 0;$a < count($coords)-1;$a++) { imagesmoothline($plaatje, $coords[$a]["x"] , $coords[$a]["y"] , $coords[$a+1]["x"] , $coords[$a+1]["y"], $lijn); imagesmoothline($plaatje, $coords2[$a]["x"] , $coords2[$a]["y"] , $coords2[$a+1]["x"] , $coords2[$a+1]["y"], $lijn2); } imagerectangle($plaatje, $rand_links, $rand_boven, ($rand_links + $gebied_breedte), ($rand_boven + $gebied_hoogte), $zwart); imagestring($plaatje, 8 , ((($rand_links + $rand_rechts + $gebied_breedte) / 2) - ((strlen($grafiek_titel) / 2) * 8)) , ($rand_boven / 2) - 8 , $grafiek_titel , $zwart); imagestringup($plaatje, 8 , 4 , ($rand_boven + $gebied_hoogte), "Tijden" ,$zwart); imagestring($plaatje, 8 , (($gebied_breedte + $rand_links) / 2) , ($rand_boven + $gebied_hoogte + ($rand_onder*0.6)), "Datum" ,$zwart); ImagePNG($plaatje); ImageDestroy($plaatje); // functie voor de anti-aliasing van de grafieklijn function imagesmoothline ( $image , $x1 , $y1 , $x2 , $y2 , $color ) { $colors = imagecolorsforindex ( $image , $color ); if ( $x1 == $x2 ) { imageline ( $image , $x1 , $y1 , $x2 , $y2 , $color ); // Vertical line } else { $m = ( $y2 - $y1 ) / ( $x2 - $x1 ); $b = $y1 - $m * $x1; if ( abs ( $m ) <= 1 ) { $x = min ( $x1 , $x2 ); $endx = max ( $x1 , $x2 ); while ( $x <= $endx ) { $y = $m * $x + $b; $y == floor ( $y ) ? $ya = 1 : $ya = $y - floor ( $y ); $yb = ceil ( $y ) - $y; $tempcolors = imagecolorsforindex ( $image , imagecolorat ( $image , $x , floor ( $y ) ) ); $tempcolors['red'] = $tempcolors['red'] * $ya + $colors['red'] * $yb; $tempcolors['green'] = $tempcolors['green'] * $ya + $colors['green'] * $yb; $tempcolors['blue'] = $tempcolors['blue'] * $ya + $colors['blue'] * $yb; if ( imagecolorexact ( $image , $tempcolors['red'] , $tempcolors['green'] , $tempcolors['blue'] ) == -1 ) imagecolorallocate ( $image , $tempcolors['red'] , $tempcolors['green'] , $tempcolors['blue'] ); imagesetpixel ( $image , $x , floor ( $y ) , imagecolorexact ( $image , $tempcolors['red'] , $tempcolors['green'] , $tempcolors['blue'] ) ); $tempcolors = imagecolorsforindex ( $image , imagecolorat ( $image , $x , ceil ( $y ) ) ); $tempcolors['red'] = $tempcolors['red'] * $yb + $colors['red'] * $ya; $tempcolors['green'] = $tempcolors['green'] * $yb + $colors['green'] * $ya; $tempcolors['blue'] = $tempcolors['blue'] * $yb + $colors['blue'] * $ya; if ( imagecolorexact ( $image , $tempcolors['red'] , $tempcolors['green'] , $tempcolors['blue'] ) == -1 ) imagecolorallocate ( $image , $tempcolors['red'] , $tempcolors['green'] , $tempcolors['blue'] ); imagesetpixel ( $image , $x , ceil ( $y ) , imagecolorexact ( $image , $tempcolors['red'] , $tempcolors['green'] , $tempcolors['blue'] ) ); $x ++; } } else { $y = min ( $y1 , $y2 ); $endy = max ( $y1 , $y2 ); while ( $y <= $endy ) { $x = ( $y - $b ) / $m; $x == floor ( $x ) ? $xa = 1 : $xa = $x - floor ( $x ); $xb = ceil ( $x ) - $x; $tempcolors = imagecolorsforindex ( $image , imagecolorat ( $image , floor ( $x ) , $y ) ); $tempcolors['red'] = $tempcolors['red'] * $xa + $colors['red'] * $xb; $tempcolors['green'] = $tempcolors['green'] * $xa + $colors['green'] * $xb; $tempcolors['blue'] = $tempcolors['blue'] * $xa + $colors['blue'] * $xb; if ( imagecolorexact ( $image , $tempcolors['red'] , $tempcolors['green'] , $tempcolors['blue'] ) == -1 ) imagecolorallocate ( $image , $tempcolors['red'] , $tempcolors['green'] , $tempcolors['blue'] ); imagesetpixel ( $image , floor ( $x ) , $y , imagecolorexact ( $image , $tempcolors['red'] , $tempcolors['green'] , $tempcolors['blue'] ) ); $tempcolors = imagecolorsforindex ( $image , imagecolorat ( $image , ceil ( $x ) , $y ) ); $tempcolors['red'] = $tempcolors['red'] * $xb + $colors['red'] * $xa; $tempcolors['green'] = $tempcolors['green'] * $xb + $colors['green'] * $xa; $tempcolors['blue'] = $tempcolors['blue'] * $xb + $colors['blue'] * $xa; if ( imagecolorexact ( $image , $tempcolors['red'] , $tempcolors['green'] , $tempcolors['blue'] ) == -1 ) imagecolorallocate ( $image , $tempcolors['red'] , $tempcolors['green'] , $tempcolors['blue'] ); imagesetpixel ( $image , ceil ( $x ) , $y , imagecolorexact ( $image , $tempcolors['red'] , $tempcolors['green'] , $tempcolors['blue'] ) ); $y ++; } } } } ?> |