從資料庫中讀出的$x, $y, $z為何不能產生圖形呢

來源:互聯網
上載者:User
從資料庫中讀出的$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 頭嗎?你怎麼說沒有呢?
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.