|
|
|
สอบถามการเขียนโค้ดค้นหาแบบค้นหา คนละตารางค่ะ ตัวแปรอยู่คนละตารางค่ะ |
|
|
|
|
|
|
|
เป็นหน้าแสดงรายการครุภัณฑ์ ต้องการค้นหา ตัวแบบ dep_id ต้องการใช้ตัวแปร dep_name ค่ะเก็ยชื่อแผนกอะ เวลาค้นหาชื่อแผนกค่ะ
ช่วยหน่อยนะคะ
show_dura2.php
Code (PHP)
<?
//ob_start();
session_start();
if(!session_is_registered("user_login"))// ตรวจสอบว่าผ่านการ login หรือไม่
{
header('location:../../index.php'); // กลับหน้า login
exit();
}
?>
<?
//$db="salebook";
?>
<!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=utf-8" />
<title>แสดงข้อมูลผู้ใช้</title>
<?
include("../connect.inc.php");
mysql_query("SET NAMES UTF8");
$sql="select * from tb_user where username='$user_login';";
$result = mysql_query( $sql );
$record=mysql_fetch_array ($result);
$id= $record['id'];
$name= $record['name'];
$lastname = $record['lastname'];
$su_id=$record['su_id'];
?>
<style>
a:hover{text-decoration:none;color:red}
a{text-decoration:none;color:blue}
a:link{text-decoration:none;color:#3366FF}
a:vlink{text-decoration:none;color:#0000FF}
.style1 {color: #FFFFFF}
</style>
<style type="text/css">
<!--
.style1 {
font-family: "MS Sans Serif";
font-size: 14px;
}
.style2 {font-family: "MS Sans Serif"; font-size: 14px; color: #FFFFFF; }
.style6 {font-family: "MS Sans Serif"; font-size: 14px; color: #0A51F5; }
.style11 {color: #990000}
.style14 {color: #FFFFFF}
.style14 { font-family: "MS Sans Serif";
font-size: 14px;
}
.style17 {color: #0A51F5}
.style20 {
font-family: "MS Sans Serif";
font-size: 14px;
}
body {
background-image: url(file:///C|/AppServ/image/bg.jpg);
}
.style23 {color: #FF6600}
.style3 {color: #FF0000}
.style26 {font-size: 14px}
.style28 {font-family: "MS Sans Serif"; font-size: 14px; color: #FF0000; }
.style33 {font-family: "MS Sans Serif"; font-size: 14px; color: #990000; }
-->
</style>
</head>
<body topmargin="0"><center>
<table width="100%" border="0" cellpadding="0" cellspacing="0" style="border-bottom:1px solid #0099ff; border-left:1px solid #0099ff; border-right:1px solid #0099ff; border-top:1px solid #0099ff" bgcolor="#FFFFFF">
<!--DWLayoutTable-->
<tr> </tr>
<tr>
<td width="23" height="48"> </td>
<td width="4"> </td>
<td width="842"></td>
<td width="96"></td>
<td width="28"> </td>
</tr>
<tr>
<td height="38"> </td>
<td colspan="2" valign="top"><span class="style1">
<span class="style14"><span class="style17"><img src="../image/last.gif" width="23" height="18" /> <a href="show_dura2.php"> แสดงข้อมูลครุภัณฑ์</a></span></span>
<span class="style17"><span class="style23"><font
face="Microsoft Sans Serif, MS Sans Serif, sans-serif" size="2"><a href="add_user.php">|</a></font></span> <a href="add_dura.php">เพิ่มข้อมูลครุภัณฑ์</a></span> <span class="style14"><span class="style17">เข้าสู่ระบบ โดย</span> <span class="style3"><? echo $name; ?> <? echo $lastname; ?></span> <span class="style17">สถานะการเข้าใช้งาน คือ</span> <span class="style3"> <? $sql2="select su_name from status_user where su_id=$su_id";
$db_query2=mysql_db_query($db,$sql2);
$result2 = mysql_fetch_array($db_query2);
$su_name = $result2[su_name];
echo"$su_name";?></span></span>
<hr>
</span></td>
<td></td>
<td></td>
</tr>
<tr>
<td height="30"> </td>
<td> </td>
<td> </td>
<td> </td>
<td><?
$db="hotpital";
include("../connect.inc.php");
mysql_query ("SET NAMES UTf8");
//if($Del=="del"){
// for($i=0;$i<$rows;$i++){
// if($checkdel[$i]==null)continue;
// $sql="DELETE FROM tb_user WHERE id='$checkdel[$i]';";
// mysql_query($sql);
//}
//}
if($Search=="search"){
$TxtSearch=trim($TxtSearch);
if(isset($TxtSearch)){
if($page==null)$page=1;
//"select * from tb_user,department,status_user where id=$id and tb_user.dep_id = department.dep_id and tb_user.su_id = status_user.su_id";
$sql="SELECT * FROM dura,department WHERE ((d_id LIKE '%$TxtSearch%') or (d_name LIKE '%$TxtSearch%') or (dep_name.department LIKE '%$TxtSearch%')) order by d_id asc";
$result=mysql_query($sql);
$rowsOfPage=mysql_num_rows($result);
$sql="SELECT * FROM dura WHERE ((d_id LIKE '%$TxtSearch%') or (d_name LIKE '%$TxtSearch%') or (dep_name.department LIKE '%$TxtSearch%')) order by d_id asc LIMIT ".(($page-1)*20).",20";
$result=mysql_query($sql);
$rows=mysql_num_rows($result);
mysql_query ("SET NAMES UTF8");
}
} else{
if($page==null)$page=1;
$sql="SELECT * FROM dura";//order by username asc ";
$result=mysql_query($sql);
$rowsOfPage=mysql_num_rows($result);
$sql="SELECT * FROM dura order by d_name asc LIMIT ".(($page-1)*20).",20";
$result=mysql_query($sql);
$rows=mysql_num_rows($result);
}
?></td>
</tr>
<tr>
<td height="255"> </td>
<td> </td>
<td valign="top"><table width="109%" border="0" cellpadding="0" cellspacing="0" style="border-bottom:1px solid #0099ff; border-left:1px solid #0099ff; border-right:1px solid #0099ff; border-top:1px solid #0099ff" bgcolor="#FFFFFF">
<!--DWLayoutTable-->
<tr>
<td width="913" height="2"></td>
</tr>
<tr>
<td height="237" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0" style="border-bottom:1px solid #0099ff; border-left:1px solid #0099ff; border-right:1px solid #0099ff; border-top:1px solid #0099ff" bgcolor="#F7F7F7">
<!--DWLayoutTable-->
<tr>
<td height="17" colspan="4" valign="top" bgcolor="#FF66FF"><div align="center" class="style2">รายการข้อมูลผู้ใช้</div></td>
</tr>
<tr>
<td width="49" height="18"></td>
<td width="712"></td>
<td width="3"></td>
<td width="41"></td>
</tr>
<tr>
<td height="28" colspan="2" valign="top"><form name="form1" method="post" action="show_dura2.php">
<div align="right"><span class="style6">ค้นหาจาก (หมายเลขครุภัณฑ์ - ชื่อครุภัณฑ์ - แผนก)</span>
<span class="style17">
<label> </label>
</span>
<label>
<input name="TxtSearch" type="text" id="TxtSearch">
</label>
<label>
<input type="submit" name="Submit" value="ค้นหา">
<input name="Search" type="hidden" id="Search" value="search">
</label>
</div>
</form></td>
<td></td>
<td></td>
</tr>
<tr>
<td height="26"></td>
<td colspan="2" valign="top">
<div align="right">
<? if($TxtSearch!=""){ ?>
<font face="MS Sans Serif, Tahoma, sans-serif" color="#990000" size="2">ผลการสืบค้นมีทั้งหมด <? echo $rows;?> รายการ</font>
<? } else{?>
<? }?>
</div></td>
<td> </td>
</tr>
<tr>
<td height="49"></td>
<td valign="top"><table width="99%" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="708" height="41" valign="top"><table width="100%" border="1" align="center" cellpadding="2" cellspacing="0" bordercolor="#2D96FF" bgcolor="#2D96FF">
<tr>
<td width="46" height="22" bgcolor="#FF6699"><div align="center"><span class="style2">ลำดับที่</span></div></td>
<td width="225" bgcolor="#FF6699"><div align="center" class="style2 style7">เลขที่ครุภัณฑ์</div></td>
<td width="329" bgcolor="#FF6699"><div align="center" class="style9 style26 style14">ชื่อครุภัณฑ์</div></td>
<td width="79" bgcolor="#FF6699"><div align="center" class="style9 style26 style14">ประจำแผนก</div></td>
<td width="85" bgcolor="#FF6699"><span class="style2">ดูรายละเอียด</span></td>
</tr>
<?
for($i=0;$i<$rows;$i++){
$d_id=mysql_result($result,$i,"d_id");
$d_name=mysql_result($result,$i,"d_name");
$dep_id=mysql_result($result,$i,"dep_id");
?>
<tr bgcolor="<? if($i%2==0)echo "#CEE7FF"; else echo "#FFFFFF";?>">
<td><div align="center" class="style1 style20"><span class="style11"><? echo $i+1+($page-1)*20;?></span></div></td>
<td width="225" align=""><div align="center" class="style33"><? echo $d_id ?></div></td>
<td width="329"><div align="left" class="style33"><? echo $d_name ?></div></td>
<td width="79"><div align="center" class="style33"><? $sql2="select dep_name from department where dep_id=$dep_id";
$db_query2=mysql_db_query($db,$sql2);
$result2 = mysql_fetch_array($db_query2);
$dep_name = $result2[dep_name];
echo $dep_name;?></div></td>
<td width="85"><a href="show_dura1.php?d_id=<? echo $d_id;?>" class="style28"><span class="style11">รายละเอียด</span></a></td>
<tr>
<? }?>
</tr>
</table></td>
</tr>
</table></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td height="32"></td>
<td> </td>
<td></td>
<td></td>
</tr>
<tr>
<td height="18"></td>
<td valign="top">
<div align="center"><font color="#0000FF" size="2" face="MS Sans Serif"><strong>หน้า
<?
if($rowsOfPage%20>0)$p=1; else $p=0;
for($i=1;$i<=$rowsOfPage/20+$p;$i++)echo "<a href=?page=$i&Search=$Search&TxtSearch=$TxtSearch> $i|</a> ";
?></strong> </font></div></td>
<td></td>
<td></td>
</tr>
<tr>
<td height="56"></td>
<td><a href="../logoff.php">ออกจากระบบ</a></td>
<td></td>
<td></td>
</tr>
</table></td>
</tr>
</table></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td height="61"> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
</body></center>
</html>
<script language="JavaScript">
function edit(id){
var vArgs = new Array(1);
vArgs[0] = parent.gHelperName;
var windowInsert=window.showModalDialog( "popup.php?link=edit_user.php?up="+id, vArgs, "dialogwidth:440px;dialogHeight:270px;status:no;resizeable:no;help:no;scroll:no" );
if(windowInsert!="") form1.submit();
}
form1.focus();
</script>
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2011-03-24 23:40:03 |
By :
หน่อย |
View :
1127 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
คนล่ะตารางให้ใช้ UNION ครับ
|
|
|
|
|
Date :
2011-03-25 09:10:14 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
แล้ววิธีการเขียนแบบค้นหาอ่ะค่ะ จากที่ให้โค้ดไปจะเขียนแบบไหนค่ะ
|
|
|
|
|
Date :
2011-03-25 10:09:57 |
By :
หน่อย |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|