JpGraph Error: HTTP headers have already been sent.
Caused by output from file fview_report_cashflow_detail.php at line 10.
Explanation:
HTTP headers have already been sent back to the browser indicating the data as text before the library got a chance to send it's image HTTP header to this browser. This makes it impossible for the library to send back image data to the browser (since that would be interpretated as text by the browser and show up as junk text).
Most likely you have some text in your script before the call to Graph::Stroke(). If this texts gets sent back to the browser the browser will assume that all data is plain text. Look for any text, even spaces and newlines, that might have been sent back to the browser.
For example it is a common mistake to leave a blank line before the opening "<?php".
codeที่ดิฉันเขียนไว้ดังนี้
Code (PHP)
<?php
include("JpGraph/src/jpgraph.php");
include("JpGraph/src/jpgraph_line.php");
$project =$_REQUEST['DeptCode'];
include("db/connect.php");
include("function/funcdate.php");
$sql="SELECT o.DeptCode,o.ProjectCode, o.Amount,o.Description ,d.DeptName,o.StartDate
FROM openproject AS o INNER JOIN department AS d ON o.DeptCode = d.DeptCode
where o.ProjectCode='$project'";
$tebleopenproject =mysql_query($sql) or die("Error : $sql".mysql_error());
while($data1 = mysql_fetch_array($tebleopenproject)) {
$deptcodeO = $data1["DeptCode"];
$projectO = $data1["1"];
$amountO = $data1["2"];
$descriptionO = $data1["3"];
$depnameO = $data1['4'];
$startdateO = $data1['5'];
list($oyear,$omonth,$oday) =explode("-",$startdateO,3);
$oyear1 = $oyear+543;
}
//**********************************************************************************************************
$firstmonth = $omonth;
$firstyear = $oyear1;
$tmonth = $firstmonth;
$tyear = $firstyear;
$jobtype = array();
for ($i=1; $i<=12; $i++) {
if ($tmonth == 13 ) {
$tmonth = 1;
$tyear = $tyear + 1;
}
$jobtype[$i][1] = $tmonth; //1 ==> month
$jobtype[$i][2] = $tyear; // 2 ==> Year
$jobtype[$i][3] = 0.00; // 3 ==> amountpi
$jobtype[$i][4] = 0.00; // 4 ==> amountpo
$jobtype[$i][5] = 0.00; // 5 ==> amountai
$jobtype[$i][6] = 0.00; // 6 ==> amountao
$tmonth = $tmonth + 1;
}
$sql ="SELECT ProjectCode, year(TransDate), month(TransDate), sum(AmountCash)
FROM cashflow
WHERE TypeCode ='P' AND TransType='I' AND ProjectCode ='$project'
GROUP BY ProjectCode, year(TransDate), month(TransDate)
Order by year(TransDate) ASC, month(TransDate) ASC ";
$teblecashpi =mysql_query($sql) or die("Error : $sql".mysql_error());
$countpi = mysql_num_rows($teblecashpi);
while($data2 = mysql_fetch_array($teblecashpi)){
$projectpi =$data2['ProjectCode'];
$tyear = $data2["1"];
$tmonth = $data2["2"];
$sumamountpi = $data2["3"];
if ($firstyear == $tyear) { $i = ($tmonth - $firstmonth) + 1;}
if ($firstyear < $tyear) { $i = (12 - $firstmonth)+1 + $tmonth;}
$jobtype[$i][3] = $data2["3"];
}
//**********************************************************************************************************
$sql ="SELECT ProjectCode, year(TransDate), month(TransDate), sum(AmountCash)
FROM cashflow
WHERE TypeCode ='P' AND TransType='O' AND ProjectCode ='$project'
GROUP BY ProjectCode, year(TransDate), month(TransDate)
Order by year(TransDate) ASC, month(TransDate) ASC ";
$teblecashpo =mysql_query($sql) or die("Error : $sql".mysql_error());
while($data3 = mysql_fetch_array($teblecashpo)){
$projectpo =$data3['ProjectCode'];
$tyear = $data3["1"];
$tmonth = $data3["2"];
$sumamountpo = $data3["3"];
if ($firstyear == $tyear) { $i = ($tmonth - $firstmonth) + 1;}
if ($firstyear < $tyear) { $i = (12 - $firstmonth)+1 + $tmonth;}
$jobtype[$i][4] = $data3["3"];
}
//**********************************************************************************************************
$sql ="SELECT ProjectCode,year(TransDate),month(TransDate),sum(AmountCash)
FROM cashflow
WHERE TypeCode ='A' AND TransType='I' AND ProjectCode ='$project' AND TaxInvoiceNo <>''
GROUP BY ProjectCode, year(TransDate), month(TransDate)
Order by year(TransDate) ASC, month(TransDate) ASC ";
$teblecash =mysql_query($sql) or die("Error : $sql".mysql_error());
while($data4 = mysql_fetch_array($teblecash)){
$projectai =$data4['ProjectCode'];
$tyear = $data4["1"];
$tmonth = $data4["2"];
$sumamountai = $data4["3"];
if ($firstyear == $tyear) { $i = ($tmonth - $firstmonth) + 1;}
if ($firstyear < $tyear) { $i = (12 - $firstmonth)+1 + $tmonth;}
$jobtype[$i][5] = $data4["3"];
}
//**********************************************************************************************************
$sql ="SELECT ProjectCode, year(TransDate), month(TransDate), sum(AmountCash)
FROM cashflow
WHERE TypeCode ='A' AND TransType='O' AND ProjectCode ='$project' AND TaxInvoiceNo <>''
GROUP BY ProjectCode, year(TransDate), month(TransDate)
Order by year(TransDate) ASC, month(TransDate) ASC ";
$teblecashao =mysql_query($sql) or die("Error : $sql".mysql_error());
while($data5 = mysql_fetch_array($teblecashao)){
$projectao =$data5['ProjectCode'];
$tyear = $data5["1"];
$tmonth = $data5["2"];
$sumamountao = $data5["3"];
if ($firstyear == $tyear) { $i = ($tmonth - $firstmonth) + 1;}
if ($firstyear < $tyear) { $i = (12 - $firstmonth)+1 + $tmonth;}
$jobtype[$i][6] = $data5["3"];
}
?>
<table width="100%" border="0">
<tr>
<td colspan="3" align="center"><strong>ประมาณการกระแสเงินสดเทียบกับกระแสเงินสดของโครงการ </strong></td>
</tr>
<tr>
<td width="25%"><strong><font size="2">ฝ่าย <?= $deptcodeO." ".$depnameO;?>
</font></strong></td>
<td width="42%"><strong><font size="2">โครงการ <?= $project." ". $descriptionO;?>
</font></strong></td>
<td width="33%"><strong><font size="2">มูลค่าโครงการ <?= number_format($amountO,2);?> บาท(ไม่รวมภาษีมูลค่าเพิ่ม)</font></strong></td>
</tr>
</table>
<?php
$g = new Graph(300,250);
$g->SetScale("textlin");
$title=iconv('TIS-620','UTF-8',"ประมาณการกระแสเงินสดเทียบกับกระแสเงินสดของโครงการ");
$g->title->Set($title);
$g->title->SetFont(FF_JASMINE,FS_BOLD,16);
$labels = array("ม.ค.","ก.พ.","มี.ค.","เม.ย.","พ.ค.","มิ.ย.");
for ($i =0; $i < count($labels); $i++) {
$labels[$i] = iconv('TIS-620','UTF-8',$labels[$i]);
}
$g->xaxis->SetTickLabels($labels);
$g->xaxis->SetFONT(FF_CORDIA,FS_NORMAL,14);
$g->xaxis->SetLabelAngle(45);
$data6 = array(300,250,425,300,175,250);
$line1 = new LinePlot($data6);
$data7 = array(150,200,175,300,250,275);
$line2 = new LinePlot($data7);
$line1->value->Show();
$line1->mark->SetType(MARK_FILLEDCIRCLE);
$line1->SetLegend("Product 1");
$line2->value->Show();
$line2->mark->SetType(MARK_SQUARE);
$line2->SetLegend("Product 2");
$g->Add($line1);
$g->Add($line2);
$g->Stroke ();
?>
<?
mysql_close($conn);
?>
<a href="fview_report_cashflow_depart.php?DeptCode=<? echo $deptcodeO;?>">ออก</a>
</body>
</html>