The $x read from the database, $y, $z Why can't I generate a graph?

Source: Internet
Author: User
Read the $x from the database, $y, $z Why can't I generate a graph?

Require (".. /comm/conn.php "); Reading data from the database section
$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; Generate a chart section
$height = 200;
$width = 200;

$y 1= $height-intval ($x/$total * $height, 10);
$y 2= $height-intval ($y/$total * $height, 10);
$y 3= $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, $y 1,3* $width/10, $height-2, $red);
Imagefilledrectangle ($im, $width/10, $y 2,6* $width/10, $height-2, $blue);
Imagefilledrectangle ($im, 7* $width/10, $y 3,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);
?>

------Solution--------------------
Output $x $y $z See what it is? Or is there a problem with your SQL?
------Solution--------------------
Header (' content-type:image/png ');
Header lowercase
------Solution--------------------
If your #1, #2的补充说明是真实的, then
1. Remove the last?> in the conn.php file
2, confirm that two files do not have a BOM header
3. Confirm $x + $y + $z! = 0
------Solution--------------------
That would be weird, comment out the header and look at it.
Header (' content-type:image/png ');
------Solution--------------------
$s = file_get_contents (' http://www.yisee.org/00Home/Messagegraph.php ');
Print_r (Unpack (' h* ', $s));

Get
Array ([1] = efbbbf89504e470d0a1a0a0000000d49484452000000c8000000c80802 ....

This EFBBBF is not the BOM head? What did you say?
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.