linechart with php

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
teevee
Posts: 9
Joined: Tue 07 Apr 2009, 08:15
Location: Tampere / Finland

linechart with php

#1 Post by teevee »

I have weird problem with php coding. I don't know if it's a Puppy/hiawatha/php related, or if it's just a lack of my knowledge...


I have html file with entry "<img src="pic_Kayrat.php" />"

I have some for loops in pic_Kayrat.php. If I run the page code without

Code: Select all

header ("Content-type: image/png"); imagepng($im);
so, as a normal php page. Everything works fine.
If I run it as a image, it prints nothing.

I have code example:

Code: Select all

for ($j = 1; $j < count($Aika); $j++) {  echo "what ever"; }
where $Aika is an array. In normal page code it echoes everything I want.

Code: Select all

for ($j = 1; $j < count($Aika); $j++) {  imageline($im, 50, 100, 500, 100, $blue); }
$blue is handled earlier. This line does not show up.

If I use

Code: Select all

for ($j = 1; $j < 15; $j++) {  imageline($im, 50, 100, 500, 100, $blue); }
where I replaced count($Aika) with number 15, line shows up in picture.

Does anybody have a glue what is happening in my code?
Why my variables are not valid?

teevee
Posts: 9
Joined: Tue 07 Apr 2009, 08:15
Location: Tampere / Finland

#2 Post by teevee »

Now I have some kind of "solution" to this problem.

Everything is messed up by my mysql queries. If I do queries in normal function and echoing results on screen, the result is as wanted. If I do queries in this pic_Kayrat.php file (which should draw a line chart), query gives the wanted result and some weird markings (special characters ?) at the end of the result. I can draw the result as a string to the chart. Trim-function helps only when I draw the string. I cannot use the result variable (not even the trimmed one). I don't know why.

So, now I do my queries in a function which is handled before the <img>-tag. I save results in a text file. Then I read the text file in the pic_Kayrat.php file. After that, I have to do the trim-stuff and everything works like a charm.

Now I hope this "solution" is helpful for others.

Post Reply