2014-11-14 59 views
-1

我想显示使用imagettftext()的1图像中的多个字段,我从MySQL数据库中检索数据,但我似乎无法让它工作我需要它的方式。我需要它在图像的不同区域显示不同的字段。如何显示图像中的多个数据库行

到目前为止,我尝试过,而且foreach。

while($row = mysql_fetch_assoc($query)) 
{ 
    $username = $row['PLAYER_NAME']; 
} 
imagettftext($im, 25, 0, 25, 52, $text_color, $font, $username); 
imagettftext($im, 25, 0, 25, 138, $text_color, $font, $username); 
imagettftext($im, 25, 0, 25, 229, $text_color, $font, $username); 

当前输出: 字段1 字段1 字段1

上的图像。

相反,我希望它显示Field1,Field2和Field3。那可能吗?如果是这样,只要给我正确的方向将是一个巨大的帮助。

我一直在为此尝试3天左右,但没有运气。

感谢

+0

我不知道我很明白你在问什么。您只需从数据库中检索'$ username',然后将其添加到图像三次。如果你想添加其他字段,那么你所需要做的就是在你的while循环中检索它们,并修改对'imagettftext()'的调用以使用这些字段 – andrewsi 2014-11-14 15:47:48

回答

0

$username是每个函数调用相同,所以你每次都会得到明显相同的文字。 Perhpas你应该考虑读取DB数据到这样一个数组:

$usernames = array(); 
while($row = mysql_fetch_assoc($query)) 
{ 
    $usernames[] = $row['PLAYER_NAME']; 
} 
imagettftext($im, 25, 0, 25, 52, $text_color, $font, $usernames[0]); 
imagettftext($im, 25, 0, 25, 138, $text_color, $font, $usernames[1]); 
imagettftext($im, 25, 0, 25, 229, $text_color, $font, $usernames[2]); 
相关问题