WARNING:MYSQL_FETCH_ASSOC (): supplied argument is not a valid MySQL result resource in E:\phpser\AppServ\www\mzgz1.php on Line 115
Jpgraph error:http headers have already been sent.
caused by output from the file mzgz1.php at line 115.
Explanation:
HTTP headers has already been sent back to the browser indicating the data as text before the library got a chance to Sen D It ' s image HTTP header to this browser. This makes it impossible for the library to send back image data to the browser (since, would be interpretated as text By the browser and show up as junk text).
Most likely are some text in your script before the call to Graph::stroke (). If This texts gets sent back to the browser the browser would assume that all data is plain text. Look for any text, even spaces and newlines, that might has been sent back to the browser.
For example it's a common mistake to leave a blank line before the opening "
The code is:
Ini_set (' Date.timezone ', ' Asia/shanghai '); ' Asia/shanghai ' for Shanghai time zone
$day =date ("y-m-d"); Get Current date
$timer =date ("h:00:00");//Get the current time
$yestday =date ("y-m-d", Strtotime ("-1 day"));//Get Yesterday time
$conn =mysql_connect (' localhost ', ' root ', ' root ');
mysql_select_db ("Pm25", $conn);
mysql_query ("Set names UTF8");
$arr =mysql_query ("Select Pm25,time from Ceshi where data= ' $day '", $conn); Query date for today result assignment to array arr
$arr 1=mysql_query ("Select Pm25,time from Ceshi where Data= $yestday", $conn); Query date is yesterday result assignment to array arr1
$time =array (
"0" = "00:00:00",
"1" = "01:00:00",
"2" = "02:00:00",
"3" = "03:00:00",
"4" = "04:00:00",
"5" = "05:00:00",
"6" = "06:00:00",
"7" = "07:00:00",
"8" = "08:00:00",
"9" = "09:00:00",
"Ten" = "10:00:00",
"One" = "11:00:00",
"+" = "12:00:00",
"+" = "13:00:00",
"+" = "14:00:00",
"All" and "15:00:00",
"+" = "16:00:00",
"+" = "17:00:00",
"+" = "18:00:00",
"+" = "19:00:00",
"+" = "20:00:00",
"+" = "21:00:00",
"All" = "22:00:00",
"All" = "23:00:00"
);
$PM 25=array ("0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0");
$PM 25today=array ("0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", " 0 ");
$PM 25yestday=array ("0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0" , "0");
while ($result =mysql_fetch_assoc ($arr)) {
echo "Yes2";
for ($j =0; $j <>
echo "Yes1";
if ($result [' Time ']== $time [$j]} {
$PM 25today[$j]= $result [' PM25 '];//store today's Pm2.5
echo "Yes";
}
}
}
while ($result =mysql_fetch_assoc ($arr 1)) {
echo "Yes2";
for ($j =0; $j <>
echo "Yes1";
if ($result [' Time ']== $time [$j]} {
$PM 25yestday[$j]= $result [' PM25 '];//store yesterday's Pm2.5
echo "Yes";
}
}
}
for ($i =0; $i <>
if ($pm 25[$i]==0) {
$PM 25today[$i]= $pm 25today[$i -1];//get today PM25 data
}
}
$a 1=array ("0 points", "1 Points", "2 Points", "3 points", "4 Points", "5 points", "6 points", "7 Points", "8 points", "9 points", "10 points", "11 points", "12 points", "13 points", "point at 14," "15 points," 16 points, "17 points", " 18 points "," 19 points "," 20 points "," 21 points "," 22 points "," 23 points "); Set X axis
$a =array ("0 points", "1 Points", "2 Points", "3 points", "4 Points", "5 points", "6 points", "7 Points", "8 points", "9 points", "10 points", "11 points", "12 points", "13 points", "point at 14," "15 points," 16 points, "17 points", " 18 points "," 19 points "," 20 points "," 21 points "," 22 points "," 23 points "); Set X axis
if ($timer = = "23:00:00") {
$PM 25[$i]= $pm 25today[$i];
if ($pm 25[0]==0) {
$arr =null;
$daytimer = 0;
while ($arr ==null) {
$daytimer + +;
$day =date ("y-m-d", Strtotime ("-$daytimer Day"));
$arr =mysql_query ("Select Pm25 from Ceshi where Data= $day", $conn);
}
$a 3=mysql_num_rows ($arr);
$result =mysql_fetch_assoc ($arr [$a 3]);//Go to the last record
$PM 25[0]= $result [' PM25 '];
}
}
else{//initialization
$m = 0;
$yestimer =date ("h:00:00", Strtotime ("+1 Hour"));//24 hours ago
for ($j =0; $j <>
if ($timer = = $time [$j]) {
$m = $j;//mark the current time position
}
}
for ($i =0; $i <>
if ($pm 25[$i]==0) {
$PM 25yestday[$i]= $pm 25yesday[$i -1];//get yesterday PM25 data
}
}
$m 1=23-$m;
$m 2=23-$m;
for ($j =0; $j <>
$PM 25[$j]= $pm 25yestday[24-$m 1];
$m 1= $m;
}
for ($i =0; $i <>
$PM 25[$m 2]= $pm 25today[$i];
$m 2++;
}
if ($pm 25[0]==0) {
$arr =null;
$daytime = 3;
while ($arr ==null) {
$day 3=date ("y-m-d", Strtotime ("-$daytime Day"));
$arr =mysql_query ("Select Pm25 from Ceshi where Data= $day 3", $conn);
$daytime + +;
}
$a 4=mysql_num_rows ($arr);
$result =mysql_fetch_assoc ($arr [$a 4]);//Go to the last record
$PM 25[0]= $result [' PM25 '];
}
For ($j =23-$m; $j <>
$m 1= $j-$m;
$a [$j]= $a 1[$m 1];
}
for ($j =0; $j <23-$m; $j + +) {
$a [$j]= $a 1[$n];
$n = $n +1;
}
}
Draw a line chart with PHP
Include ("e:/phpser/appserv/jpgraph/jpgraph/jpgraph.php");
Include ("e:/phpser/appserv/jpgraph/jpgraph/jpgraph_line.php");
$datay = Array (109,120,120,97,112,135,135,106,106,106,204,124,124,124,119,109,118,118,197,155,142,142,136,137) ; The populated data
$datay = $pm 25;
$graph = new Graph (700,300, "Auto"); Build Canvas
$graph->img->setmargin (50,40,30,40); Set the margins of the canvas
$graph->img->setantialiasing (); Set the smoothing state of the stitches
$graph->setscale ("Textlin"); Set scale style
$graph->setshadow ();//Create a canvas shadow
$graph->title->set ("Changes in PM2.5 value in the last 24 hours");//Set Caption
$graph->title->setfont (ff_simsun,fs_bold);//Set Title font
$graph->setmargincolor ("LightBlue");//Set the background color of the canvas to be light blue
$graph->yaxis->title->setfont (ff_simsun,fs_bold);//Set the font for the y-axis title
$graph->xaxis->setpos ("min");
$graph->yaxis->hidezerolabel ();
$graph->ygrid->setfill (True,[email protected] ', [email protected] ');
$a =array ("0 points", "1 Points", "2 Points", "3 points", "4 Points", "5 points", "6 points", "7 Points", "8 points", "9 points", "10 points", "11 points", "12 points", "13 points", "point at 14," "15 points," 16 points, "17 points", " 18 points "," 19 points "," 20 points "," 21 points "," 22 points "," 23 points "); Set X axis
$graph->xaxis->setticklabels ($a);
$graph->xaxis->setfont (Ff_simsun); Set the font for the X axis
$graph->yscale->setgrace (20);
$p 1 = new LinePlot ($datay); Create a Line chart object
$p 1->mark->settype (mark_filledcircle); Set data coordinate points as graphical markers
$p 1->mark->setfillcolor ("Red"); Set the color of the fill
$p 1->mark->setwidth (4); Set the diameter of the cylindrical marker to 4 pixels
$p 1->mark->setcolor ("Blue"); Set the stitch color to Blue
$p 1->setcenter (); Draw stitches at the center of each coordinate point on the x-axis
$graph->add ($p 1); Draw a polyline on a chart
$graph->stroke (); Output image
?>
------to solve the idea----------------------
What line is 115?
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.