|
|
|
สอบถามเรื่องการ Search แบบ JOIN 4 Tables แล้วค้นหาข้อมูลไม่ได้ครับ |
|
|
|
|
|
|
|
สอบถามเรื่องการ Search แบบ JOIN 4 Tables
คือผมมีปัญหาอยู่ว่า ปกติผม SELECT Table เดียว สามารถ Search ได้ตามปกติ แต่พอ JOIN Tables แล้วไม่สามารถ Search ได้ตามเงื่อนไขครับ ด้านล่างนี้คือ Code Search แบบ JOIN Tables ครับ
Code (PHP)
<?
include("config.4419.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=tis-620" />
<title>Select Employee for Add การลา</title>
<style type="text/css">
<!--
@import url("../Font.css");
-->
</style>
</head>
<body>
<div align="center">
<table width="774" border="0" cellspacing="0" cellpadding="0">
<tr>
<th scope="row"><table width="774" border="0" cellspacing="0" cellpadding="0">
<tr>
<th width="10" scope="row"> </th>
<td width="144"> </td>
<td width="77"> </td>
<td width="77"> </td>
<td width="77"> </td>
<td width="77"> </td>
<td width="77"> </td>
<td width="77"> </td>
<td width="77"> </td>
<td width="81"> </td>
</tr>
<tr>
<th scope="row"> </th>
<td height="25" colspan="4" class="Header_FontB"><div align="left">EMPLOYEES DATA</div></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<th scope="row"> </th>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<th scope="row"> </th>
<td colspan="9"><div align="left"><span class="Header_Table_Blue">ค้นหาพนักงานที่ต้องการลา :</span><span class="Menu_A">
<input name="txt_search" type="text" id="txt_search" value="<? $txt_search?>" size="25" maxlength="50" />
<input type="submit" name="Search" id="Search" value="Search" />
<span class="Body_Red">* ค้นหาข้อมูลพนักงานที่ต้องการล</span></span><span class="Body_Red">าเช่น รหัสพนักงาน, ชื่อ และ แผนก</span></div></td>
</tr>
<tr>
<th scope="row"> </th>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<th scope="row"> </th>
<td colspan="9"><table width="764" border="1" cellpadding="0" cellspacing="0" >
<tr>
<th width="80" height="30" bgcolor="#FFBC9B" class="Header_Table" scope="row"><div align="center">รหัสพนักงาน</div></th>
<td width="62" bgcolor="#FFBC9B" class="Header_Table"><div align="center">รหัสการลา</div></td>
<td width="159" bgcolor="#FFBC9B" class="Header_Table"><div align="center">ชื่อ-สกุล</div></td>
<td width="102" bgcolor="#FFBC9B" class="Header_Table"><div align="center">ตำแหน่ง</div></td>
<td width="171" bgcolor="#FFBC9B" class="Header_Table"><div align="center">แผนก</div></td>
<td width="100" bgcolor="#FFBC9B" class="Header_Table"><div align="center">วันเริ่มงาน</div></td>
<td width="74" bgcolor="#FFBC9B" class="Header_Table"><div align="center">จัดการ</div></td>
</tr>
<?
//SELECT customer.*,audit.* FROM customer
//LEFT JOIN audit ON customer.CustomerID = audit.CustomerID
include("config.4419.php");
$i=1;
$sql="SELECT DISTINCT(personalinfo.PRS_E_CARD),personalinfo.*,empfile.*,payrollinfo.*,promote.* FROM personalinfo
LEFT JOIN empfile ON (personalinfo.PRS_EMP=empfile.EMP_KEY)
LEFT JOIN payrollinfo ON (empfile.EMP_KEY=payrollinfo.PRI_EMP)
LEFT JOIN promote ON (payrollinfo.PRI_EMP=promote.PRO_EMP)
WHERE PRS_NO LIKE '%$txt_search%' OR EMP_NAME LIKE '%$txt_search%' OR promote.PRO_DEPT like '%$txt_search%' GROUP BY personalinfo.PRS_E_CARD ORDER BY personalinfo.PRS_NO DESC";
//where Invoice_No like '%$txt_search%' or Number_No like '%$txt_search%'
//GROUP BY table1.id_name ORDER BY table1.id_name DESC
//SELECT * FROM tumbol
// LEFT JOIN amphur ON (tumbol.amphur_id=amphur.amphur_id)
//LEFT JOIN province ON (amphur.province_id=province.province_id)
$dbname="payroll_v4";
$db_query=mysql_db_query($dbname,$sql);
while ( $rs = mysql_fetch_array ( $db_query ) )
{
$PRS_NO=$rs[PRS_NO];
$EMP_NAME=$rs[EMP_NAME];
$EMP_SURNME=$rs[EMP_SURNME];
$PRO_TITLE=$rs[PRO_TITLE];
$PRO_DEPT=$rs[PRO_DEPT];
$PRI_START_D=$rs[PRI_START_D];
?>
<tr>
<th height="25" bgcolor="#FFE6D9" class="Menu_A" scope="row"><div align="center"><? echo "$PRS_NO";?></div></th>
<td bgcolor="#FFE6D9" class="Menu_A"><div align="center"><? echo"$i";?></div></td>
<td bgcolor="#FFE6D9" class="Menu_A"><div align="left"><a href="index.php?id=frmInsert&emp_id=<?=$_GET=$PRS_NO?>"><? echo "$EMP_NAME $EMP_SURNME";?></a></div></td>
<td bgcolor="#FFE6D9" class="Menu_A"><div align="left"><? echo "$PRO_TITLE";?></div></td>
<td bgcolor="#FFE6D9" class="Menu_A"><div align="left"><? echo "$PRO_DEPT";?></div></td>
<td bgcolor="#FFE6D9" class="Menu_A"><div align="left"><? echo "$PRI_START_D";?></div></td>
<td bgcolor="#FFE6D9" class="Menu_A"><div align="center"><img src="picture/b_edit.png" alt="edit" width="16" height="16" /> <img src="picture/b_drop.png" alt="del" width="16" height="16" /></div></td>
</tr>
<?
$i++;
};
?>
</table></td>
</tr>
<tr>
<th scope="row"> </th>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<th scope="row"> </th>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table></th>
</tr>
</table>
</div>
</body>
</html>
Tag : PHP, MySQL, HTML/CSS, JavaScript, WebService, Windows
|
|
|
|
|
|
Date :
2013-04-01 15:39:29 |
By :
TotEcom |
View :
857 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date :
2013-04-01 15:45:30 |
By :
TotEcom |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ได้แล้วครับเส้นผมบังภูเขาแท้ ๆ ลืมใส่ Form ครับ
นี่ Code ครับ
Code (PHP)
<?
include("config.4419.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=tis-620" />
<title>Select Employee for Add การลา</title>
<style type="text/css">
<!--
@import url("../Font.css");
-->
</style>
</head>
<body>
<div align="center">
<table width="774" border="0" cellspacing="0" cellpadding="0">
<tr>
<th scope="row"><table width="774" border="0" cellspacing="0" cellpadding="0">
<tr>
<th width="10" scope="row"> </th>
<td width="144"> </td>
<td width="77"> </td>
<td width="77"> </td>
<td width="77"> </td>
<td width="77"> </td>
<td width="77"> </td>
<td width="77"> </td>
<td width="77"> </td>
<td width="81"> </td>
</tr>
<tr>
<th scope="row"> </th>
<td height="25" colspan="4" class="Header_FontB"><div align="left">EMPLOYEES DATA</div></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<th scope="row"> </th>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<form name="frim_Select_emp" id="" method="post">
<tr>
<th scope="row"> </th>
<td colspan="9"><div align="left"><span class="Header_Table_Blue">ค้นหาพนักงานที่ต้องการลา :</span><span class="Menu_A">
<input name="txt_search" type="text" id="txt_search" value="<? $txt_search?>" size="25" maxlength="50" />
<input type="submit" name="Search" id="Search" value="Search" />
<span class="Body_Red">* ค้นหาข้อมูลพนักงานที่ต้องการล</span></span><span class="Body_Red">าเช่น รหัสพนักงาน, ชื่อ และ แผนก</span></div></td>
</tr>
</form>
<tr>
<th scope="row"> </th>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<th scope="row"> </th>
<td colspan="9"><table width="764" border="1" cellpadding="0" cellspacing="0" >
<tr>
<th width="80" height="30" bgcolor="#FFBC9B" class="Header_Table" scope="row"><div align="center">รหัสพนักงาน</div></th>
<td width="62" bgcolor="#FFBC9B" class="Header_Table"><div align="center">รหัสการลา</div></td>
<td width="159" bgcolor="#FFBC9B" class="Header_Table"><div align="center">ชื่อ-สกุล</div></td>
<td width="102" bgcolor="#FFBC9B" class="Header_Table"><div align="center">ตำแหน่ง</div></td>
<td width="171" bgcolor="#FFBC9B" class="Header_Table"><div align="center">แผนก</div></td>
<td width="100" bgcolor="#FFBC9B" class="Header_Table"><div align="center">วันเริ่มงาน</div></td>
<td width="74" bgcolor="#FFBC9B" class="Header_Table"><div align="center">จัดการ</div></td>
</tr>
<?
//SELECT customer.*,audit.* FROM customer
//LEFT JOIN audit ON customer.CustomerID = audit.CustomerID
include("config.4419.php");
$i=1;
$sql="SELECT DISTINCT(personalinfo.PRS_E_CARD),personalinfo.*,empfile.*,payrollinfo.*,promote.* FROM personalinfo
LEFT JOIN empfile ON (personalinfo.PRS_EMP=empfile.EMP_KEY)
LEFT JOIN payrollinfo ON (empfile.EMP_KEY=payrollinfo.PRI_EMP)
LEFT JOIN promote ON (payrollinfo.PRI_EMP=promote.PRO_EMP)
WHERE PRS_NO LIKE '%$txt_search%' OR EMP_NAME LIKE '%$txt_search%' OR promote.PRO_DEPT like '%$txt_search%' GROUP BY personalinfo.PRS_E_CARD ORDER BY personalinfo.PRS_NO DESC";
//where Invoice_No like '%$txt_search%' or Number_No like '%$txt_search%'
//GROUP BY table1.id_name ORDER BY table1.id_name DESC
//SELECT * FROM tumbol
// LEFT JOIN amphur ON (tumbol.amphur_id=amphur.amphur_id)
//LEFT JOIN province ON (amphur.province_id=province.province_id)
$dbname="payroll_v4";
$db_query=mysql_db_query($dbname,$sql);
while ( $rs = mysql_fetch_array ( $db_query ) )
{
$PRS_NO=$rs[PRS_NO];
$EMP_NAME=$rs[EMP_NAME];
$EMP_SURNME=$rs[EMP_SURNME];
$PRO_TITLE=$rs[PRO_TITLE];
$PRO_DEPT=$rs[PRO_DEPT];
$PRI_START_D=$rs[PRI_START_D];
?>
<tr>
<th height="25" bgcolor="#FFE6D9" class="Menu_A" scope="row"><div align="center"><? echo "$PRS_NO";?></div></th>
<td bgcolor="#FFE6D9" class="Menu_A"><div align="center"><? echo"$i";?></div></td>
<td bgcolor="#FFE6D9" class="Menu_A"><div align="left"><a href="index.php?id=frmInsert&emp_id=<?=$_GET=$PRS_NO?>"><? echo "$EMP_NAME $EMP_SURNME";?></a></div></td>
<td bgcolor="#FFE6D9" class="Menu_A"><div align="left"><? echo "$PRO_TITLE";?></div></td>
<td bgcolor="#FFE6D9" class="Menu_A"><div align="left"><? echo "$PRO_DEPT";?></div></td>
<td bgcolor="#FFE6D9" class="Menu_A"><div align="left"><? echo "$PRI_START_D";?></div></td>
<td bgcolor="#FFE6D9" class="Menu_A"><div align="center"><img src="picture/b_edit.png" alt="edit" width="16" height="16" /> <img src="picture/b_drop.png" alt="del" width="16" height="16" /></div></td>
</tr>
<?
$i++;
};
?>
</table></td>
</tr>
<tr>
<th scope="row"> </th>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<th scope="row"> </th>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table></th>
</tr>
</table>
</div>
</body>
</html>
|
|
|
|
|
Date :
2013-04-01 16:02:51 |
By :
totEcom |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date :
2013-04-01 17:08:32 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|