Php 如何在图像中显示多个数据库行
我试图使用imagettftext()在一个图像中显示多个字段,我正在从MySQL数据库检索数据,但我似乎无法让它按我需要的方式工作。我需要它在图像的不同区域显示不同的字段 到目前为止,我已经试过了Php 如何在图像中显示多个数据库行,php,mysql,image,Php,Mysql,Image,我试图使用imagettftext()在一个图像中显示多个字段,我正在从MySQL数据库检索数据,但我似乎无法让它按我需要的方式工作。我需要它在图像的不同区域显示不同的字段 到目前为止,我已经试过了 while($row = mysql_fetch_assoc($query)) { $username = $row['PLAYER_NAME']; } imagettftext($im, 25, 0, 25, 52, $text_color, $font, $username); imag
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天的实验,但是没有运气
谢谢
在每次函数调用中都是相同的,因此每次显然都会得到相同的文本。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]);
我不太清楚你在问什么。您只需从数据库中检索
$username
,然后将其添加到图像中三次。如果要添加其他字段,则只需在while循环中检索它们,并修改对imagettftext()
的调用以使用这些字段