INNER JOIN???

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
apek
Forum Commoner
Posts: 96
Joined: Tue Jan 06, 2004 11:19 pm
Location: Holiday Plaza Johor Bahru

INNER JOIN???

Post 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?
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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).
Last edited by McGruff on Tue Aug 09, 2005 11:57 pm, edited 1 time in total.
User avatar
apek
Forum Commoner
Posts: 96
Joined: Tue Jan 06, 2004 11:19 pm
Location: Holiday Plaza Johor Bahru

...

Post 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???
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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)
?>
Last edited by McGruff on Tue Aug 09, 2005 11:56 pm, edited 1 time in total.
User avatar
apek
Forum Commoner
Posts: 96
Joined: Tue Jan 06, 2004 11:19 pm
Location: Holiday Plaza Johor Bahru

.........

Post by apek »

i'm sorry...
i try that...
but still the same....
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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?
User avatar
apek
Forum Commoner
Posts: 96
Joined: Tue Jan 06, 2004 11:19 pm
Location: Holiday Plaza Johor Bahru

..........

Post 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%">&nbsp;</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 : &nbsp; <?=$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 : &nbsp; <?=$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: &nbsp; 
                    <?=$maklumat["idMajor"]?>
                    </font> </td>
                </tr>
                <tr> 
                  <td> <font size="2" color="black"> ID Minor: &nbsp; 
                    <?=$maklumat["idMinor"]?>
                    </font> </td>
                </tr>
                <tr> 
                  <td> <font size="2" color="black"> Minor Name: &nbsp; 
                    <?=$maklumat["minorName"]?>
                    </font> </td>
                </tr>
                <tr> 
                  <td> <font size="2" color="black"> Stok : &nbsp; 
                    <?=$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>&nbsp;</p>
              <p>&nbsp;</p>
              <p>&nbsp;</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>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</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>&nbsp;&nbsp;&nbsp;Jumlah Masa Kerosakan</strong></font></td>
        </tr>
        <tr>
          <td><font size="2"><strong>&nbsp;&nbsp;&nbsp;
          _______Hari ________Jam _________Minit<br>
          </strong></font></td>
        </tr>
      </table>    
    </td>
    <td width="50%">
    <table align="center" width="100%">
        <tr>
          <td><font size="2"><strong>&nbsp;&nbsp;&nbsp;</strong></font></td>
        </tr>
    </table>
    </td>
  </tr>
  <tr>
    <td width="100%" colspan="2">
    <p>
     <font size="2"><strong>&nbsp;&nbsp;&nbsp;Maklumat Kerja</strong></font>
    </p>
    <p>&nbsp;</p>
    
    <table align="center" width="100%">
     <tr>
      <td width="70%">
        <font size="2" color="black"><strong>
          &nbsp;&nbsp;&nbsp;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>
  &nbsp;&nbsp;&nbsp;Kerja Sempurna Disahkan Oleh : 
</strong></font>     
</p>
<table border="0" width="100%">
  <tr>
    <td width="25%">&nbsp;</td>
    <td width="25%">&nbsp;</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>&nbsp;
  <br><!--
  <a href="../mainframe.htm"><b> KEMBALI</b></a>&nbsp;
-->
</center>
</form>
<pre><?php
print_r($_POST); // print_r()
?></pre> 
</body>
</html>
from here,the problem in this topic occurs...
so any idea?
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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?
User avatar
apek
Forum Commoner
Posts: 96
Joined: Tue Jan 06, 2004 11:19 pm
Location: Holiday Plaza Johor Bahru

...

Post 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...
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

How high is your error reporting? Is it set to E_ALL?

Mac
User avatar
apek
Forum Commoner
Posts: 96
Joined: Tue Jan 06, 2004 11:19 pm
Location: Holiday Plaza Johor Bahru

.......

Post 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....
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
User avatar
apek
Forum Commoner
Posts: 96
Joined: Tue Jan 06, 2004 11:19 pm
Location: Holiday Plaza Johor Bahru

.......

Post 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...
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
User avatar
apek
Forum Commoner
Posts: 96
Joined: Tue Jan 06, 2004 11:19 pm
Location: Holiday Plaza Johor Bahru

.........

Post by apek »

errr...

i get this:

Resource id #2

what is that?

such a long query just bring out that short output???
Post Reply