总结
豆包 AI 助手文章总结

从数据库中读出的$x, $y, $z为何不能生成图形呢

php中文网
发布: 2016-06-13 13:06:38
原创
1064人浏览过

从数据库中读出的$x, $y, $z为什么不能生成图形呢

require("../Comm/Conn.php"); //从数据库读取数据部分
  $result = mysqli_query($mysql, "select count(*) as nega from message where attitude=-1");
  $row = mysqli_fetch_assoc($result);
  $x=(int)$row['nega'];
  $result = mysqli_query($mysql, "select count(*) as zero from message where attitude=0");
  $row = mysqli_fetch_assoc($result);
  $y=(int)$row['zero'];
  $result = mysqli_query($mysql, "select count(*) as posi from message where attitude=1");
  $row = mysqli_fetch_assoc($result);
  $z=(int)$row['posi'];
mysqli_free_result($result);
mysqli_close($mysql); 


$total=$x+$y+$z; //生成统计图部分
$height=200;
$width=200;

$y1=$height-intval($x/$total*$height,10); 
$y2=$height-intval($y/$total*$height,10); 
$y3=$height-intval($z/$total*$height,10); 

$im=imagecreatetruecolor($width,$height);
$white=imagecolorallocate($im,255,255,255);
$black=imagecolorallocate($im,0,0,0);
$red=imagecolorallocate($im,255,0,0);
$blue=imagecolorallocate($im,0,0,255);
$green=imagecolorallocate($im,0,255,0);

imagefill($im,0,0,$white);
imagerectangle($im,0,0,$width-1,$height-1,$black);
imagefilledrectangle($im,$width/10,$y1,3*$width/10,$height-2,$red);
imagefilledrectangle($im,4*$width/10,$y2,6*$width/10,$height-2,$blue);
imagefilledrectangle($im,7*$width/10,$y3,9*$width/10,$height-2,$green);

imagestring($im,5,30,180,$x,$white);
imagestring($im,5,90,180,$y,$white);
imagestring($im,5,150,180,$z,$red);

Header('Content-type:image/png');
imagepng($im);
imagedestroy($im);
?>

------解决方案--------------------
输出 $x $y $z看看是什么?还是你的sql有问题?
------解决方案--------------------
Header('Content-type:image/png');
header小写
------解决方案--------------------
如果你的 #1、#2的补充说明是真实的,那么
1、去掉 Conn.php 文件中最后的 ?>
2、确认两个文件均没有 BOM 头
3、确认 $x+$y+$z != 0
------解决方案--------------------
那就比较怪异了,注释掉 header 看看
//Header('Content-type:image/png');
------解决方案--------------------
$s = file_get_contents('http://www.yisee.org/00Home/Messagegraph.php');
print_r(unpack('H*', $s));

得到
Array ( [1] => efbbbf89504e470d0a1a0a0000000d49484452000000c8000000c80802....

这个 efbbbf 不就是 BOM 头吗?你怎么说没有呢?

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
豆包 AI 助手文章总结
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号