problems with related query...
Posted: Tue Feb 03, 2004 6:03 pm
i want to display a chart that will display by month if the user choose the year...
this is my snippet of code:
first ,user choose a year...
than at the $viewCheck, the query will select only months within the year selected by the user..
id is an id represents 01,02,03....12(months)...
$senarai["waktuTamat"] is date in timestamp format....i query it earlier..
and i want to select all id(or months) that same to the months in $senarai["waktuTamat"] ..which i queried earlier...
can u help me?
the chart dont display..
if it does,it only show only the first month....
i'm sorry if the code mess up a bit...
it is ok in my editor....
this is my snippet of code:
Code: Select all
<?php
include("../inc/config.php");
include("phpchartdir.php");
session_start();
//===============FUNCTION AREA===============================
function query($query, $link, $line, $file)
{
$result = mysql_query($query);
if (empty($result) && ini_get('display_errors') == 1)
{
echo mysql_error().": ";
echo mysql_errno()."<br />\n";
echo $query."<br />\n";
echo "@ $line in $file\n";
}
return $result;
}
$tahun=$_POST["year"];
?>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Zend Studio">
</HEAD>
<BODY>
<form name="myform" action="failureRate1.php" method="post">
<table width="100%" border="1" bgcolor="#666666" bordercolor="#333333" align="center">
<tr>
<td align="center">
<font face="verdana" size="2" color="white"><b>
KADAR KEROSAKAN MESIN BERDASARKAN BULAN
</b></font>
</td>
</tr>
</table>
<br>
<?php
//****************PANGGIL SEMUA PEKERJA***********
$viewall=query("Select noTag,waktuTamat from repairbreakdown WHERE noTag = '{$_POST["noTag"]}' AND DATE_FORMAT(waktuTamat,'%Y') = '$tahun'", $link, __LINE__, __FILE__);
$senarai=mysql_fetch_array($viewall);
?>
<?php
if (empty($senarai))
{
?>
<br>
<table width="100%" border="0"align="center">
<tr>
<td align="center">
<font face="verdana" size="2" color="red"><b>
Maaf ! Tiada maklumat di dalam pangkalan data
</b></font>
</td>
</tr>
</table>
<P><BR>
<CENTER>
<A HREF="failureRateMenu.php">
<FONT FACE="VERDANA" SIZE="2"><STRONG>
KEMBALI
</STRONG></FONT>
</A>
</CENTER>
<?php
}
else
{
?>
<?php
$bil=1;
while($senarai=mysql_fetch_array($viewall))
{
$viewCheck=query("SELECT id FROM tempfailure WHERE id = DATE_FORMAT('{$senarai["waktuTamat"]}','%m') ORDER BY id", $link, __LINE__, __FILE__);
$periksa=mysql_fetch_array($viewCheck);
if (date("m",$senarai["waktuTamat"])==$periksa["id"])
{
$nilai=$periksa["jumlah"]+1;
$SQLupd=query("UPDATE tempfailure SET jumlah = '$nilai' WHERE id =DATE_FORMAT('{$senarai["waktuTamat"]}','%m')", $link, __LINE__, __FILE__);
}
$bil=$bil+1;
}
echo date("m",$senarai["waktuTamat"]);
?>
</table>
<P><BR>
<?php
$viewCheck1=query("SELECT bulan,failureRate FROM tempfailure order by id", $link, __LINE__, __FILE__);
?>
<?php
while($periksa1=mysql_fetch_array($viewCheck1, MYSQL_NUM)) {
$array1[]=$periksa1[0];
$array2[]=$periksa1[1];
?>
<?php
}
$_SESSION["firstquarter"]=$array1;
$_SESSION["firstquarter2"]=$array2;
#The data for the pie chart
$data =$_SESSION["firstquarter2"];
#The labels for the pie chart
$labels=$_SESSION["firstquarter"];
#Create a XYChart object of size 300 x 280 pixels
$c = new XYChart(600, 380);
#Set the plotarea at (45, 30) and of size 200 x 200 pixels
$c->setPlotArea(230, 30, 300, 300);
#Add a title to the chart using 12 pts Arial Bold Italic font
$c->addTitle(" Kadar Kerosakan Mesin", "arialbi.ttf", 12);
#Add a title to the y axis
$c->yAxis->setTitle("Failure Rate");
#Add a title to the x axis
$c->xAxis->setTitle("Bulan");
#Add a blue (0x6666ff) 3D line chart layer using the give data
$barLayerObj = $c->addBarLayer($data, 0x6666ff);
$barLayerObj->set3D();
#Set the x axis labels using the given labels
$c->xAxis->setLabels($labels);
#Create the image and save it in a temporary location
$chart1URL = $c->makeSession("chart1");
#Create an image map for the chart
$imageMap = $c->getHTMLImageMap("xystub.php", "", "title='{label}:RM{value|0}K'");
?>
<IMG SRC="failureRateImg.php?<?PHP ECHO $chart1URL?>" BORDER="0" USEMAP="#map1"> <MAP NAME="map1">
<?PHP ECHO $imageMap?>
</MAP>
<table width="50%" border="1" align="center">
<tr>
<td align="center">
<table align="center" width="100%">
<tr>
<td align="center">
<font face="verdana" size="1"><b>Petunjuk Graf</b></font>
</td>
</tr>
<tr>
<td width="50%" align="center">
<font face="verdana" size="1"><b><font color="red">Paksi X : </font>Bulan Operasi Pada Tahun <?php echo $_POST["year"]; ?></b></font>
</td>
</tr>
<tr>
<td width="50%" align="center">
<font face="verdana" size="1"><b><font color="red">Paksi Y : </font>Jumlah Kerosakan (Failure Rate) Pada Bulan</b></font>
</td>
</tr>
</table>
</td>
</tr>
</table>
<br>
<INPUT TYPE="HIDDEN" name="noTag" value="<?php $_POST["noTag"];?>">
<INPUT TYPE="HIDDEN" name="year" value="<?php $_POST["year"];?>">
<center>
<input style="BACKGROUND-COLOR: #cccccc; BORDER-BOTTOM: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; COLOR: #333333; FONT-FAMILY: Verdana; FONT-SIZE: 7pt" type="submit" value="ANALISA FAILURE RATE" name="submit">
</center>
<?php
}
?>
</form>
<center><font face="verdana" color="navy" size="2"><b>Sila klik pada sektor untuk mengetahui nilai carta</b></font></center>
</BODY>
</HTML>than at the $viewCheck, the query will select only months within the year selected by the user..
id is an id represents 01,02,03....12(months)...
$senarai["waktuTamat"] is date in timestamp format....i query it earlier..
and i want to select all id(or months) that same to the months in $senarai["waktuTamat"] ..which i queried earlier...
can u help me?
the chart dont display..
if it does,it only show only the first month....
i'm sorry if the code mess up a bit...
it is ok in my editor....