Page 1 of 3
INNER JOIN???
Posted: Thu Jan 15, 2004 11:44 am
by apek
this is my snippet of code:
Code: Select all
function query($query,$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;
}
?>
<html>
<head>
<meta NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</head>
<body>
<form name="myform">
<?
$status= "Diproses";
$jenis="BM";
$SQL = query("UPDATE aduankerosakan SET status = '$status' WHERE idAduan = '{$_POST["id"]}' ", __LINE__, __FILE__);
$maklumat = query("SELECT * FROM aduankerosakan INNER JOIN tpartminor ON aduankerosakan.idMajor = tpartminor.idMajor WHERE aduankerosakan.idAduan = '{$_POST["id"]}'", __LINE__, __FILE__);
but i think something wrong with my SQL statement above...
the UPDATE process seems failed(no changes in database),and all information taken from $maklumat is not shown...
but no error appears...
should i change my SQL statement?
Posted: Thu Jan 15, 2004 12:22 pm
by McGruff
Try concatenation to fix the problem with $_POST, eg:
Code: Select all
<?php
"UPDATE aduankerosakan SET status = '" . $status . "' WHERE idAduan = '" . $_POST['id'] . "' "
?>
I never mix dollar vars in with strings since it's much less clear what's going on.
In your custom query function (logging line & file with the query is nice) test for $result == false not empty($result).
...
Posted: Thu Jan 15, 2004 1:00 pm
by apek
its not working...
but after i change to '" . $_GET['id'] . "' then the update is working...
but the $maklumat seems failed..
because i cant retrieve data from it..
but no eror appears...
how to fix this???
Posted: Thu Jan 15, 2004 2:04 pm
by McGruff
To get the error, you need to test for $result == false in your custom query function, ie:
Code: Select all
<?php
if ($result == false && ini_get('display_errors') == 1)
?>
.........
Posted: Thu Jan 15, 2004 9:38 pm
by apek
i'm sorry...
i try that...
but still the same....
Posted: Thu Jan 15, 2004 9:55 pm
by McGruff
With the change I suggested to the if test, errors will only be displayed if the query returns false AND display_errors = 1. What is display_errors set to?
Oh, and if id is passed via GET rather than POST did you change the $maklumat query to GET?
..........
Posted: Thu Jan 15, 2004 10:34 pm
by apek
i changed to GET for $maklumat....
but still the same...
to make it easier,i attach my two pages code
this is the first page(semakAduan.php):
Code: Select all
<?php
include("../inc/config.php");
?>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>
<form name="myform">
<table width="100%" border="1" bgcolor="#FF9900" bordercolor="#333333" align="center">
<tr>
<td align="center" bgcolor="#FFCC00"> <font face="verdana" size="2" color="white"><b>
<font color="#000000">MODUL SENARAI PAPARAN ADUAN KEROSAKAN YANG BELUM
DI BAIKPULIH </font></b></font> </td>
</tr>
</table>
<br>
<?
function query($query, $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;
}
?>
<?
//***********PANGGIL DATA DARIPADA PANGKALAN DATA******
$result=query("Select * from aduankerosakan where status = 'Baru' ", __LINE__, __FILE__);
$senarai=result;
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>
<?
}
else {
?>
<!--**********TABLE PAPARAN VIEW********************-->
<TABLE BORDER="1" WIDTH="100%" BGCOLOR="#FFFFFF" align=center cellPadding=1 cellSpacing=1 borderColor=black height=1 style="HEIGHT: 1px">
<TR ALIGN="CENTER">
<TD ALIGN="CENTER" BGCOLOR="#FFCC00"> <font face="verdana" size="2" color="white"><strong>
<font color="#000000">Bil </font></strong></font> </TD>
<TD ALIGN="CENTER" BGCOLOR="#FFCC00"> <font face="verdana" size="2" color="white"><strong>
<font color="#000000">ID Aduan </font></strong></font> </TD>
<TD ALIGN="CENTER" BGCOLOR="#FFCC00"> <font face="verdana" size="2" color="white"><strong>
<font color="#000000">Tarikh Aduan </font></strong></font> </TD>
<TD ALIGN="CENTER" BGCOLOR="#FFCC00"> <font face="verdana" size="2" color="white"><strong>
<font color="#000000">Waktu Aduan </font></strong></font> </TD>
<TD ALIGN="CENTER" BGCOLOR="#FFCC00"> <font face="verdana" size="2" color="white"><strong>
<font color="#000000">ID Major </font></strong></font> </TD>
<TD ALIGN="CENTER" BGCOLOR="#FFCC00"> <font face="verdana" size="2" color="white"><strong>
<font color="#000000">Punca </font></strong></font> </TD>
<TD ALIGN="CENTER" BGCOLOR="#FFCC00"> <font face="verdana" size="2" color="white"><strong>
<font color="#000000">Status </font></strong></font> </TD>
</TR>
<?
$bil=1;
while ($senarai = mysql_fetch_array($result, MYSQL_ASSOC))
{
?>
<TR>
<TD><font face="verdana" size="2"><?=$bil?></font></TD>
<TD><a href="semakAduan1.php?id=<?=$senarai["idAduan"]?>"><font face="verdana" size="2"><?=$senarai["idAduan"]?></font></a></TD>
<TD><font face="verdana" size="2"><?=$senarai["tarikhAduan"]?></font></TD>
<TD><font face="verdana" size="2"><?=$senarai["waktuAduan"]?></font></TD>
<TD><font face="verdana" size="2"><?=$senarai["idMajor"]?></font></TD>
<TD><font face="verdana" size="2"><?=$senarai["punca"]?></font></TD>
<TD><font face="verdana" size="2"><?=$senarai["status"]?></font></TD>
</TR>
<?
$bil=$bil+1;
}
?>
</table>
<?
}
?>
<P><BR>
</form>
<pre><?php
print_r($_POST); // print_r()
?></pre>
</BODY>
</HTML>
and this is the second page(semakAduan1.php),where i have to get the id from semakAduan.php):
Code: Select all
<?php
extract($_GET);
include("../inc/config.php");
include("../inc/veryuseful.inc");
function query($query,$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;
}
?>
<html>
<head>
<meta NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</head>
<body>
<form name="myform">
<?
//'{$_GET["id"]}'
$status= "Diproses";
$jenis="BM";
$result = query("UPDATE aduankerosakan SET status = '" . $status . "' WHERE idAduan = '" . $_GET['id'] . "'", __LINE__, __FILE__);
$maklumat = query("SELECT * FROM aduankerosakan INNER JOIN tpartminor ON aduankerosakan.idMajor = tpartminor.idMajor WHERE aduankerosakan.idAduan ='" . $_GET['id'] . "'", __LINE__, __FILE__);
//----------------------------------------------------
// CAPAI DATA DARIPADA PANGKALAN DATA
// NAMA TABLE : PEKERJA
//----------------------------------------------------
$pekerja = query("SELECT * FROM temployee where status = 'BMW'", __LINE__, __FILE__);
//----------------------------------------------------
// CAPAI DATA DARIPADA PANGKALAN DATA
// NAMA TABLE : tpartminor
//----------------------------------------------------
$komponen = query("SELECT * FROM tpartminor", __LINE__, __FILE__);
?>
<table align="center" border="1" width="100%">
<tr>
<td align="center">
<table width="100%" align="center" border="0">
<tr>
<td align="center" width="25%"> </td>
<td align="center" width="50%"><img src="../images/logo.gif" WIDTH="170" HEIGHT="53"></td>
<td align="center" width="25%">
<font size="2" color="black"><strong>
TARIKH : <?=$maklumat["tarikhAduan"]?>
</strong></font>
</td>
</tr>
</table>
<br>
<table align="center" width="100%">
<tr>
<td width="70%">
<font size="2" color="black"><strong>
BORANG LAPORAN KERJA PEMBAIKAN KEROSAKAN MESIN
</strong></font>
</td>
<td align="right">
<font size="2" color="black"><strong>
NO ID ADUAN : <?=$maklumat["idAduan"]?>
</strong></font>
</td>
</table>
<br>
<table border="1" width="100%">
<tr>
<td width="50%">
<table width="100%" align="center">
<tr>
<td> <font size="2" color="black"><strong> Maklumat Mesin </strong></font>
</td>
</tr>
<tr>
<td> <font size="2" color="black"> Nama Aset : CENTRIFUGAL PUMP</font></td>
</tr>
<tr>
<td> <font size="2" color="black"> ID Major:
<?=$maklumat["idMajor"]?>
</font> </td>
</tr>
<tr>
<td> <font size="2" color="black"> ID Minor:
<?=$maklumat["idMinor"]?>
</font> </td>
</tr>
<tr>
<td> <font size="2" color="black"> Minor Name:
<?=$maklumat["minorName"]?>
</font> </td>
</tr>
<tr>
<td> <font size="2" color="black"> Stok :
<?=$maklumat["jmlhStok"]?>
</font> </td>
</tr>
</table>
</td>
<td width="50%" rowspan="2">
<p> <font size="2"><strong>Deskripsi Tugas</strong></font> <br>
<?=$maklumat["punca"]?></textarea>
</p>
<p> </p>
<p> </p>
<p> </p>
</td>
</tr>
</table>
<br>
<table align="center" width="100%">
<tr>
<td width="70%">
<font size="2" color="black"><strong>
SENARAI KOMPONEN
</strong></font>
</td>
</table>
<br>
<table border="1" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td align="center"><strong>Kod Pekerja</strong></td>
<td align="center"><strong>Tarikh Mula</strong></td>
<td align="center"><strong>Masa Mula</strong></td>
<td align="center"><strong>Tarikh Tamat</strong></td>
<td align="center"><strong>Masa Tamat</strong></td>
<td align="center" width="30%"><strong>Nama Komponen</strong></td>
<td align="center"><strong>Kuantiti</strong></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
<br>
<table border="1" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td width="50%">
<table align="center" width="100%">
<tr>
<td><font size="2"><strong> Jumlah Masa Kerosakan</strong></font></td>
</tr>
<tr>
<td><font size="2"><strong>
_______Hari ________Jam _________Minit<br>
</strong></font></td>
</tr>
</table>
</td>
<td width="50%">
<table align="center" width="100%">
<tr>
<td><font size="2"><strong> </strong></font></td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="100%" colspan="2">
<p>
<font size="2"><strong> Maklumat Kerja</strong></font>
</p>
<p> </p>
<table align="center" width="100%">
<tr>
<td width="70%">
<font size="2" color="black"><strong>
Penyelia Yang Terlibat :__________________________
</strong></font>
</td>
<td align="left">
<font size="2" color="black"><strong>
Tarikh :____________________
</strong></font>
</td>
</table>
</td>
</tr>
</table>
<br>
<p>
<font size="2" color="black"><strong>
Kerja Sempurna Disahkan Oleh :
</strong></font>
</p>
<table border="0" width="100%">
<tr>
<td width="25%"> </td>
<td width="25%"> </td>
<td width="25%">
<font size="2" color="black"><strong>
Tarikh Pengesahan
</strong></font>
</td>
<td width="25%">
<font size="2" color="black"><strong>
Tandatangan
</strong></font>
</td>
</tr>
<tr>
<td width="25%">
<font size="2" color="black"><strong>
Subkontrak
</strong></font>
</td>
<td width="25%">______________</td>
<td width="25%">______________</td>
<td width="25%">______________</td>
</tr>
<tr>
<td width="25%">
<font size="2" color="black"><strong>
PMSB
</strong></font>
</td>
<td width="25%">______________</td>
<td width="25%">______________</td>
<td width="25%">______________</td>
</tr>
<tr>
<td width="25%">
<font size="2" color="black"><strong>
Hospital
</strong></font>
</td>
<td width="25%">______________</td>
<td width="25%">______________</td>
<td width="25%">______________</td>
</tr>
</table>
<br><br>
</td></tr>
</table>
<p align="center">
<font face="verdana" size="2" color="red"><strong>
* Sila cetak dan simpan salinan laporan kerja ini untuk proses penyimpanan maklumat kerosakan
dan pengesahan...
</strong></font>
</p>
<center>
<a href="javascript:if (window.print != null) { window.print(); } else { alert('Harap Maaf, pelayar anda tidak dapat menyokong fungsi ini. Sila pilih Print daripada menu File.'); }"><b> CETAK</b></a>
<br><!--
<a href="../mainframe.htm"><b> KEMBALI</b></a>
-->
</center>
</form>
<pre><?php
print_r($_POST); // print_r()
?></pre>
</body>
</html>
from here,the problem in this topic occurs...
so any idea?
Posted: Fri Jan 16, 2004 2:35 am
by McGruff
Two pages doesn't make it any easier.. All we need are the relevant snippets - assuming you know what they are of course.
Are you getting an error for the $maklumat query?
...
Posted: Fri Jan 16, 2004 3:45 am
by apek
i already gave the relevant snippets earlier in this topic...
i just gave the two pages code for anyone reference..maybe theres something error with the flow of the form...
i did mentioned I DONT GET ANY ERROR from $maklumat query...
hmmm...i keep saying the same thing here...
pls give me solution pls...
Posted: Fri Jan 16, 2004 6:11 am
by twigletmac
How high is your error reporting? Is it set to E_ALL?
Mac
.......
Posted: Fri Jan 16, 2004 6:58 am
by apek
E_ALL?
what is that???
i dunno that...
i'm a newbie in php..
all i know since i used that custom function gave by someone in discussion forum like this,my form processing problem is solved....
but in this problem..i cant retrieve data from $maklumat to display on the aduanKerosakan.php form...but the UPDATE has no problem....
Posted: Fri Jan 16, 2004 7:09 am
by twigletmac
I'm just wondering if there are errors in the code that you're not seeing, try adding:
Code: Select all
ini_set('display_errors', 1);
error_reporting(E_ALL);
to the top of semakAduan1.php, run it and see if there are any error messages.
Mac
.......
Posted: Fri Jan 16, 2004 7:16 am
by apek
to the top of aduanKerosakan1.php..
it means it'll look like this....
Code: Select all
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
extract($_GET);
include("../inc/config.php");
include("../inc/veryuseful.inc");
.
.
.
sad but true....
still the same...
and no error appears...
Posted: Fri Jan 16, 2004 7:25 am
by twigletmac
OK, so we've sorted that the code and the SQL isn't giving an error, what do you get if you put:
Code: Select all
echo '<pre>';
print_r($maklumat );
echo '</pre>';
after
Code: Select all
$maklumat = query("SELECT * FROM aduankerosakan INNER JOIN tpartminor ON aduankerosakan.idMajor = tpartminor.idMajor WHERE aduankerosakan.idAduan ='" . $_GET['id'] . "'", __LINE__, __FILE__);
This is to check what the result is giving you.
Mac
.........
Posted: Fri Jan 16, 2004 7:35 am
by apek
errr...
i get this:
Resource id #2
what is that?
such a long query just bring out that short output???