Jump to content

[SOLVED] imagettftext + for loop


mrbuter

Recommended Posts

Hi again!

 

I'm making what I thought would be (and probably is but I'm not able to do it :P) a simple forum signature for someone using imagettftext in php. It's a shoutbox type thing where people can go to a webpage and enter their nick and comment and it'll add it into a database. Then I have the image.php file connect to the database and read the stuff from there.

 

But alas I have a problem!

 

see here:

 

it works like so

 

$text1 = blablabla
$text2 = blablabla2

(etc.)

 

then:

imagettftext($im, 10, 0, 150, 70, $black, $font, $text);
imagettftext($im, 10, 0, 40, 110, $black, $font, $text2);

 

 

I have text1 set to a nondynamic thing so that works fine. I made $text2 into:

 

$text2 = for($x=0;$x<$nbr_rangees;$x++){
"" . mysql_result($results_text,$x,"nick") . ":  " . mysql_result($results_text,$x,"comment") . "\n"; 
}

 

And I get..

 

Parse error: syntax error, unexpected T_FOR in /.../image.php on line 39

 

so what gives?

 

I guess you cant use a for loop there? But then what can I use to get the same results?

 

 

Thank you!

Link to comment
https://forums.phpfreaks.com/topic/111268-solved-imagettftext-for-loop/
Share on other sites

Make an array inside the for loop.  You can't use a for loop in the current way you have it.  And I'd personally cache the images after you make them so your server doesn't explode (not really "explode"...but it'll load kind of slowly when calling images).

make an array inside the for loop.

 

Never done this before.

 

Something like this?

 

for($x=0;$x<$nbr_rangees;$x++){
$text["2"+i] = "" . mysql_result($results_text,$x,"nick") . ":  " . mysql_result($results_text,$x,"comment") . "\n"; 
}

 

But then

 

I'd also need to put the imagettftext($im, 10, 0, 40, 110, $black, $font, $text2);

line into a loop as well right?

 

 

I'm sure I just completely butchered what an array in a for loop even is.

$text2[] = "" . mysql_result($results_text,$x,"nick") . ":  " . mysql_result($results_text,$x,"comment") . "\n";

 

 

Then you could use a foreach to go through it later.

foreach ($text2 as $inputtext) {

imagettftext($im, 10, 0, 40, 110, $black, $font, $inputtext);

}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.