在图象的生日快乐,在php的错误

时间:2017-01-15 19:19:06

标签: php mysql

我有一个mysql数据库,我想确保当它是某人的生日时,在横幅上出现了写作。 我的横幅脚本:

<?PHP
header('Content-Type: image/jpeg');

$host_db='127.0.0.1';
$Login_db='root';
$pwd_db='**********';
$bdd_name='regTS3';

$oggi= date("d/m/Y");

$conn=mysql_connect($host_db,$Login_db,$pwd_db);
mysql_select_db($bdd_name,$conn);



$result = mysql_query('SELECT * FROM `regTS3` WHERE `Anni` = '.$oggi.';');
$Data= Array();
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) 
{
	$i=0;
        $Data[$i] =  $row['Nome'];
		$i=$i+1;
}





$img = imagecreatefromjpeg("banner.jpg");

$color = ImageColorAllocate($img, 83, 196, 225);
$color2 = ImageColorAllocate($img, 83, 196, 225);

$font= "./pitt.ttf";
$font2="./verdana.ttf";

$text = date("H:i"); 
$text2 = "Test";

imagettftext($img, 28, 0, 560, 70, $color, $font, $text);
imagettftext($img, 30, 0, -150, 190, $color2, $font2, $Data[0]);

imagejpeg($img);
imagedestroy($img);
?>
我在StackOverflow上复制了“while”循环的代码,在某个人的问题中,(除了我测试的“i”变量),但我不太了解,我需要在比较日期之后给我相同的名字,不知道如何返回该行中的人的名字。 为了测试,我将当前日期设置为关注者,故意在日期列中有一个用户数据库,它具有当前日期。

1 个答案:

答案 0 :(得分:0)

你可以这样做更简单:

$result = mysql_query('SELECT Nome FROM `regTS3` WHERE DATE_FORMAT(Anni,\'%d%m\') = DATE_FORMAT(NOW(),\'%d%m\')');
$Data= Array();
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) 
{
        $Data[] =  $row['Nome'];
}

$img = imagecreatefromjpeg("banner.jpg");

$color = ImageColorAllocate($img, 83, 196, 225);
$color2 = ImageColorAllocate($img, 83, 196, 225);

$font= "./pitt.ttf";
$font2="./verdana.ttf";

$text = date("H:i"); 
$text2 = "Test";

imagettftext($img, 28, 0, 560, 70, $color, $font, $text);
if (count($Data) > 0) {
   $string = implode(" ", $Data);
   imagettftext($img, 30, 0, -150, 190, $color2, $font2, $string);
}