tampil data 3 tabel berrelasi

ra · Aug 10, 2017
sore mas mo nanya dunk
saya mau menampilkan hasil query dari 4 tabel yg terelasi misal saya masukkan medrecnya data2 yag lain keluar
tabel saya
1. datasosial(medrec(pk), nama, tgllahir)
2. kunjungan(idkunjungan(pk), medrec, diagutama, diasekunder)
3. icd10(kd_penyakit(pk), penyakit)
4. icd10b (kd_penyakit(pk), penyakit)
relasi
1. datasosial(medrec)= kunjungan(medrec)
2. kunjunagan(diagutama)=icd10(kd_penyakit)
3. kunjungan(diasekunder)=icd10b(kd_penyakit)

sql saya berjalan dimysql
SELECT kunjungan.idkunjung, kunjungan.medrec, kunjungan.masuk, kunjungan.keluar, kunjungan.jnsrawat, kunjungan.jnskunjung, kunjungan.carakeluar, kunjungan.diagutama, kunjungan.diasekunder, datasosial.nama, datasosial.tglahir, datasosial.umurthn, datasosial.umurhari, datasosial.jnskelamin, datasosial.bblahir, icd10.penyakit AS diagnosautama, icd10b.penyakit AS diagnosasekunder FROM kunjungan, datasosial, icd10, icd10b WHERE kunjungan.diagutama=icd10.kd_penyakit AND kunjungan.diasekunder=icd10b.kd_penyakit AND datasosial.medrec=kunjungan.medrec AND kunjungan.medrec='0000001'
tp kl pake scrip kede dibawah muncul keterangan "Column 'medrec' in where clause is ambiguous"
<!DOCTYPE html>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
body {
	font: 100% Verdana, Arial, Helvetica, sans-serif;
	background: #666666;
	margin: 0; /* it's good practice to zero the margin and padding of the body element to account for differing browser defaults */
	padding: 0;
	text-align: center; /* this centers the container in IE 5* browsers. The text is then set to the left aligned default in the #container selector */
	color: #000000;
}
.oneColFixCtrHdr #container {
	width: auto;  /* using 20px less than a full 800px width allows for browser chrome and avoids a horizontal scroll bar */
	background: #FFFFFF;
	margin: 0 auto; /* the auto margins (in conjunction with a width) center the page */
	border: 1px solid #000000;
	text-align: left; /* this overrides the text-align: center on the body element. */
}
.oneColFixCtrHdr #header {
	background: #DDDDDD; 
	padding: 0 10px 0 20px;  /* this padding matches the left alignment of the elements in the divs that appear beneath it. If an image is used in the #header instead of text, you may want to remove the padding. */
}
.oneColFixCtrHdr #header h1 {
	margin: 0; /* zeroing the margin of the last element in the #header div will avoid margin collapse - an unexplainable space between divs. If the div has a border around it, this is not necessary as that also avoids the margin collapse */
	padding: 10px 0; /* using padding instead of margin will allow you to keep the element away from the edges of the div */
}
.oneColFixCtrHdr #mainContent {
	padding: 0 20px; /* remember that padding is the space inside the div box and margin is the space outside the div box */
	background: #FFFFFF;
}
.oneColFixCtrHdr #footer {
	padding: 0 10px; /* this padding matches the left alignment of the elements in the divs that appear above it. */
	background:#DDDDDD;
}
.oneColFixCtrHdr #footer p {
	margin: 0; /* zeroing the margins of the first element in the footer will avoid the possibility of margin collapse - a space between divs */
	padding: 10px 0; /* padding on this element will create space, just as the the margin would have, without the margin collapse issue */
}
-->
</style></head>

<body class="oneColFixCtrHdr">

<div id="container">
  <div id="header">
    <h1>Resume</h1>
  <!-- end #header --></div>
  <div id="mainContent">
    <h1>HASIL</h1>
    
    <?php
error_reporting("E_ALL ^ E_NOTICE");
mysql_connect("localhost", "root", "");
mysql_select_db("datapx");

$bagianWhere = "";

if (isset($_POST['medrec']))
{
   $medrec = $_POST['medrec'];
   if (empty($bagianWhere))
   {
		$bagianWhere .= "medrec = '$medrec'";
   }
   else
   {
	   $bagianWhere .= " AND medrec LIKE '$medrec'";
   }
}




$query = "SELECT kunjungan.idkunjung, kunjungan.medrec, kunjungan.masuk, kunjungan.keluar, kunjungan.jnsrawat, kunjungan.jnskunjung, kunjungan.carakeluar, kunjungan.diagutama, kunjungan.diasekunder, datasosial.nama, datasosial.tglahir, datasosial.umurthn, datasosial.umurhari, datasosial.jnskelamin, datasosial.bblahir, icd10.penyakit AS diagnosautama, icd10b.penyakit AS diagnosasekunder FROM kunjungan, datasosial, icd10, icd10b WHERE kunjungan.diagutama=icd10.kd_penyakit AND kunjungan.diasekunder=icd10b.kd_penyakit AND datasosial.medrec=kunjungan.medrec AND kunjungan.medrec=".$bagianWhere;
$hasil = mysql_query($query) or die (mysql_error());


echo "<table border='1' cellpadding = '2' cellspacing = '1' align = 'left'>";
echo "<tr><td>id kunjungan</td><td><tr><td>MEDREC</td><td>NAMA</td></td><td>TGL MASUK</td><td>TGL KELUAR</td><td>JENIS KELAMIN</td><td>TGL Lahir</td><td>UMUR TAHUN</td>
	<td>UMUR HARI</td><td>JENIS KUNJUNGAN</td><td>JENIS PERAWATAN</td><td>CARA KELUAR RS</td><td>BERAT BADAN LAHIR</td><td>DIAGNOSA UTAMA</td> <td>ICD10</td><td>DIAGNOSA SEKUNDER</td><td>IC10</td></tr>";

while ($data = mysql_fetch_array($hasil))
{
   echo "<tr><td>".$data['idkunjung']."</td><td>".$data['medrec']."</td><td>".$data['nama']."</td><td>".$data['masuk']."</td><td>".$data['keluar']."</td><td>".$data['jnskelamin']."</td><td>".$data['tglahir']."</td>
   <td>".$data['umurthn']."</td><td>".$data['umurhari']."</td><td>".$data['jnskunjung']."</td><td>".$data['jnsrawat']."</td><td>".$data['carakeluar']."</td><td>".$data['bblahir']."</td><td>".$data['penyakit']."</td>
   <td>".$data['kd_penyakit']."</td><td>".$data['diasekunder']."</td><td>".$data['kd_penyakit']."</td></tr>";
}
echo "</table>";
?>
  <!-- end #mainContent --></div>
  <div id="footer">
    <table width="317" border="1" >
      <tr>
        <th width="107" height="32" align="left" scope="row">TANGGAL : </th>
        <td width="199"><span id="date"><?php print date('d-m-Y'); ?></span></td>
      </tr>
      <tr>
        <th height="40" align="left" scope="row">JAM	:</th>
        <td><script type="text/javascript">
    //set timezone
    <?php date_default_timezone_set('Asia/Jakarta'); ?>
    //buat object date berdasarkan waktu di server
    var serverTime = new Date(<?php print date('Y, m, d, H, i, s, 0'); ?>);
    //buat object date berdasarkan waktu di client
    var clientTime = new Date();
    //hitung selisih
    var Diff = serverTime.getTime() - clientTime.getTime();    
    //fungsi displayTime yang dipanggil di bodyOnLoad dieksekusi tiap 1000ms = 1detik
    function displayServerTime(){
        //buat object date berdasarkan waktu di client
        var clientTime = new Date();
        //buat object date dengan menghitung selisih waktu client dan server
        var time = new Date(clientTime.getTime() + Diff);
        //ambil nilai jam
        var sh = time.getHours().toString();
        //ambil nilai menit
        var sm = time.getMinutes().toString();
        //ambil nilai detik
        var ss = time.getSeconds().toString();
        //tampilkan jam:menit:detik dengan menambahkan angka 0 jika angkanya cuma satu digit (0-9)
        document.getElementById("clock").innerHTML = (sh.length==1?"0"+sh:sh) + ":" + (sm.length==1?"0"+sm:sm) + ":" + (ss.length==1?"0"+ss:ss);
    }
    </script>
      <body onload="setInterval('displayServerTime()', 1000);">
	<br/>
      <span id="clock"><?php print date('H:i:s'); ?></span></td>
      </tr>
    </table>
    <a href="/ridha/index.php">Kembali ke halaman Sebelumnya</a>
  <!-- end #footer --></div>
<!-- end #container --></div>
</body>
</html>
Silahkan login untuk menjawab!