|
|
|
ผมมีความต้องการค้นหาตามฟิวด์ ที่ต้องการ แต่ไม่ปรากฏผลตามที่ต้องการครับ |
|
|
|
|
|
|
|
ค้นหาตามรหัสได้ แต่ พอจะค้นหาตามชื่อแล้วไม่ปรากฏผลครับ รบกวนพี่ๆ ด้วยนะครับ
Code (PHP)
<?php
session_start();
?>
<!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"><!-- InstanceBegin template="/Templates/templet.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>ระบบการจัดการทรัพยากรมนุษย์</title>
<script language="JavaScript">
var HttPRequest = false;
function doCallAjax(Search,Page) {
HttPRequest = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
HttPRequest = new XMLHttpRequest();
if (HttPRequest.overrideMimeType) {
HttPRequest.overrideMimeType('text/html');
}
} else if (window.ActiveXObject) { // IE
try {
HttPRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
HttPRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!HttPRequest) {
alert('Cannot create XMLHTTP instance');
return false;
}
var url = 'Page_admin_Seach2.php';
var pmeters = 'mySearch='+Search +'¶m='+document.getElementById('search').value;
var pmeters = "mySearch=" + Search +"&myPage=" + Page ;
HttPRequest.open('POST',url,true);
HttPRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
HttPRequest.setRequestHeader("Content-length", pmeters.length);
HttPRequest.setRequestHeader("Connection", "close");
HttPRequest.send(pmeters);
HttPRequest.onreadystatechange = function()
{
if(HttPRequest.readyState == 3) // Loading Request
{
document.getElementById("mySpan").innerHTML = "Now is Loading...";
}
if(HttPRequest.readyState == 4) // Return Request
{
document.getElementById("mySpan").innerHTML = HttPRequest.responseText;
}
}
}
</script>
<?
include('connect.php');
$_SESSION["Username"] == "";
$strSQL = "SELECT * FROM tb_staff WHERE staff_id = '".$_SESSION["Username"]."' ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$objResult = mysql_fetch_array($objQuery);
?>
<form name="form1" method="post" action="Page_admin_seach1.php" >
<table width="1026" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<th width="1026" height="115" align="right" valign="top" scope="row"><table width="1028" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<th width="391" align="right" scope="row"><img src="images/Download-icon.png" alt="" width="90" height="90" /></th>
<th width="366" align="left" valign="middle" scope="row"><font color="black" size="+3">ค้นหาข้อมูลอาจารย์ / บุคลากร</font></th>
<th width="271" align="right" valign="top" scope="row"><table width="184" border="0" align="right" cellpadding="0" cellspacing="0">
<tr>
<th width="61" height="19" align="left" scope="row"><font color="#009900"> >> ชื่อผู้ใช้ :<a href="Page_Teacher_Update_account.php?staff_id=<?=$objResult["staff_id"];?>">
<?=$objResult["staff_name"];?>
<?=$objResult["staff_sername"];?>
</a></th>
</tr>
</table></th>
</tr>
<tr>
<th colspan="3" align="right" scope="row"><br />
<table width="900" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<th width="357" height="42" align="left" valign="middle" bgcolor="#666666" scope="row"> </th>
<th width="543" bgcolor="#666666" scope="row"><table width="441" border="0" align="right" cellpadding="0" cellspacing="0">
<tr>
<th width="123" valign="middle" scope="row"><font size="+2" color="#FFFFFF">ค้นหาตาม :</font></th>
<td width="104" valign="middle"><select name="search" id="search">
<option value="0">รหัสบุคลากร</option>
<option value="1">ชื่อ</option>
<option value="2">ที่อยู่</option>
<option value="3">เบอร์โทรศัพท์</option>
<option value="4">ตำแหน่ง</option>
</select></td>
<td width="144" valign="middle"><input type="text" name="txtSearch" id="txtSearch" value="<? echo $search?>" /></td>
<td width="42"><input type="button" name="btnSearch" id="button" value="ค้นหา" onclick="JavaScript:doCallAjax(document.getElementById('txtSearch').value,'1')"; /></td>
</tr>
</table></th>
</tr>
</table></th>
</tr>
<tr>
<th colspan="3" align="center" scope="row"> </th>
</tr>
</table></th>
</tr>
</table>
<span id="mySpan"></span>
<br />
<table width="136" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<th width="40" align="left" valign="middle" scope="row"><a href="Page_admin_Register.php"><img src="images/images (2).png" alt="" width="37" height="37" /></a></th>
<td width="56" align="center" valign="middle"><a href="Page_admin.php"><img src="images/home-icon.png" alt="" width="47" height="47" /></a></td>
<td width="40" align="right" valign="middle"><img src="images/images (1).png" alt="" width="36" height="36" /></td>
</tr>
</table>
</form>
Code (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=utf-8" />
<title>ระบบการจัดการทรัพยากรมนุษย์</title>
<style type="text/css">
body,td,th {
font-family: ThaiPetcharatSPV;
}
</style>
</head>
<body><form>
<?php
$strSearch = $_POST["mySearch"];
$strPage = $_POST["myPage"];
$param = $_POST['param'];
include ("connect.php");
$strSQL = "SELECT * FROM tb_staff WHERE staff_id LIKE '%".$strSearch."%' OR staff_name LIKE '%".$strSearch."%'";
if($param == 0)
{
$strSQL = "SELECT * FROM tb_staff WHERE staff_id LIKE '%".$strSearch."%'";
}
if($param == 1)
{
$strSQL = "SELECT * FROM tb_staff WHERE staff_name LIKE '%".$strSearch."%'";
}
/*
if($param == 2)
{
$strSQL .= "OR address LIKE '%".$strSearch."%'";
}
if($param == 3)
{
$strSQL .= "OR tel1 LIKE '%".$strSearch."%'";
}
if($param == 4)
{
$strSQL .= "OR position LIKE '%".$strSearch."%'";
}
*/
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$num_records = mysql_num_rows($objQuery); ?>
<?
$Per_Page = 5; // Per Page
$Page = $strPage;
if(!$strPage)
{
$Page=1;
}
$Prev_Page = $Page-1;
$Next_Page = $Page+1;
$Page_Start = (($Per_Page*$Page)-$Per_Page);
if($num_records<=$Per_Page)
{
$Num_Pages =1;
}
else if(($num_records % $Per_Page)==0)
{
$Num_Pages =($num_records/$Per_Page) ;
}
else
{
$Num_Pages =($num_records/$Per_Page)+1;
$Num_Pages = (int)$Num_Pages;
}
$strSQL .= "order by staff_id ASC LIMIT $Page_Start , $Per_Page ";
$objQuery = mysql_query($strSQL);
//if(!$objQuery){ echo mysql_error(); }
?>
<center>
<?php
if($num_records == 0)
echo "<font color=#FF0000 size=+2>ผลการค้นหา ไม่มีข้อมูลตรงตามที่ระบุ</font>";
?></center>
<table width="901" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="901" height="95" align="left">
<table width="902" border="0" align="center" cellpadding="0" cellspacing="2">
<tr>
<th width="125" height="39" bgcolor="#666666"><div align="center"><font size="+2" color="#FFFFFF">รหัสบุคลากร</font></div></th>
<th width="156" bgcolor="#666666"> <div align="center"><font size="+2" color="#FFFFFF">ชื่อ</font></div></th>
<th width="157" bgcolor="#666666"> <div align="center"><font size="+2" color="#FFFFFF">นามสกุล</font></div></th>
<th width="157" bgcolor="#666666"> <div align="center"><font size="+2" color="#FFFFFF">ที่อยู่</font></div></th>
<th width="131" bgcolor="#666666"> <div align="center"><font size="+2" color="#FFFFFF">เบอร์โทรศัพท์</font></div></th>
<th width="162" bgcolor="#666666"> <div align="center"><font size="+2" color="#FFFFFF">ตำแหน่ง</font></div></th>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
<tr>
<td height="25" align="center" bgcolor="#CCCCCC"><font size="5" color="#FFFFFF">
<?=$objResult["staff_id"];?>
</font></td>
<td align="center" bgcolor="#CCCCCC"><font size="5" color="#FFFFFF">
<?=$objResult["staff_name"];?>
</font></td>
<td align="center" bgcolor="#CCCCCC"><font size="5" color="#FFFFFF">
<?=$objResult["staff_sername"];?>
</font></td>
<td align="center" bgcolor="#CCCCCC"><font size="5" color="#FFFFFF">
<?=$objResult["address"];?>
</font></td>
<td align="center" bgcolor="#CCCCCC"><font size="5" color="#FFFFFF">
<?=$objResult["tel1"];?>
</font></td>
<td align="center" bgcolor="#CCCCCC"><font size="5" color="#FFFFFF">
<?=$objResult["position"];?>
</font></td>
</tr>
<?
}
?>
</table>
<font size="+2" color="#333333"><br />
</font>
<table width="897" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<th width="897" align="left" scope="row"><font size="+1" color="#333333">
ข้อมูลทั้งหมด |<?= $num_records;?>| รายการ : <?=$Num_Pages;?> หน้า :
<?
if($Prev_Page)
{
echo "<< <a href=\"JavaScript:doCallAjax(document.getElementById('txtSearch').value,'$Prev_Page')\">กลับ</a> ";
}
for($i=1; $i<=$Num_Pages; $i++)
{
if($i != $Page)
{
echo "[ <a href=\"JavaScript:doCallAjax(document.getElementById('txtSearch').value,'$i')\">$i</a> ]";
}
else
{
echo "<b> $i </b>";
}
}
if($Page!=$Num_Pages)
{
echo " <a href=\"JavaScript:doCallAjax(document.getElementById('txtSearch').value,'$Next_Page')\">ถัดไป</a> >> ";
}
?></font>
</p></th>
</tr>
</table></td>
</tr>
</table>
<p>
<?
mysql_close();
?>
</form>
</body>
</html>
Tag : PHP, MySQL, HTML/CSS, Ajax
|
|
|
|
|
|
Date :
2014-07-13 02:19:14 |
By :
san.saleah |
View :
896 |
Reply :
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองดูครับ
Code (PHP)
$strSQL = "SELECT * FROM tb_staff ";
if($param == 0)
{
$strSQL .= " WHERE staff_id LIKE '%$strSearch%' ";
}
else if($param == 1)
{
$strSQL .= " WHERE staff_name LIKE '%$strSearch%' ";
}
else if($param == 2)
{
$strSQL .= " WHERE address LIKE '%$strSearch%' ";
}
else if($param == 3)
{
$strSQL .= " WHERE tel1 LIKE '%$strSearch%' ";
}
else if($param == 4)
{
$strSQL .= " WHERE position LIKE '%$strSearch%' ";
}
|
|
|
|
|
Date :
2014-07-13 03:56:38 |
By :
arm8957 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
คุณต้องใช้ $txtSearch ไม่ใช่ $strSearch คุณส่งค่าตัวแปล $txtSearch นี้มา แต่มาใช้ $strSearch ไม่ได้
หรือเอาแบบนี้
Code (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=utf-8" />
<title>ระบบการจัดการทรัพยากรมนุษย์</title>
<style type="text/css">
body,td,th {
font-family: ThaiPetcharatSPV;
}
</style>
</head>
<body><form>
<?php
$strSearch = $_POST["txtSearch"];
$strPage = $_POST["myPage"];
$param = $_POST['param'];
include ("connect.php");
$strSQL = "SELECT * FROM tb_staff WHERE staff_id LIKE '%".$strSearch."%' OR staff_name LIKE '%".$strSearch."%'";
if($param == 0)
{
$strSQL = "SELECT * FROM tb_staff WHERE staff_id LIKE '%".$strSearch."%'";
}
if($param == 1)
{
$strSQL = "SELECT * FROM tb_staff WHERE staff_name LIKE '%".$strSearch."%'";
}
/*
if($param == 2)
{
$strSQL .= "OR address LIKE '%".$strSearch."%'";
}
if($param == 3)
{
$strSQL .= "OR tel1 LIKE '%".$strSearch."%'";
}
if($param == 4)
{
$strSQL .= "OR position LIKE '%".$strSearch."%'";
}
*/
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$num_records = mysql_num_rows($objQuery); ?>
<?
$Per_Page = 5; // Per Page
$Page = $strPage;
if(!$strPage)
{
$Page=1;
}
$Prev_Page = $Page-1;
$Next_Page = $Page+1;
$Page_Start = (($Per_Page*$Page)-$Per_Page);
if($num_records<=$Per_Page)
{
$Num_Pages =1;
}
else if(($num_records % $Per_Page)==0)
{
$Num_Pages =($num_records/$Per_Page) ;
}
else
{
$Num_Pages =($num_records/$Per_Page)+1;
$Num_Pages = (int)$Num_Pages;
}
$strSQL .= "order by staff_id ASC LIMIT $Page_Start , $Per_Page ";
$objQuery = mysql_query($strSQL);
//if(!$objQuery){ echo mysql_error(); }
?>
<center>
<?php
if($num_records == 0)
echo "<font color=#FF0000 size=+2>ผลการค้นหา ไม่มีข้อมูลตรงตามที่ระบุ</font>";
?></center>
<table width="901" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="901" height="95" align="left">
<table width="902" border="0" align="center" cellpadding="0" cellspacing="2">
<tr>
<th width="125" height="39" bgcolor="#666666"><div align="center"><font size="+2" color="#FFFFFF">รหัสบุคลากร</font></div></th>
<th width="156" bgcolor="#666666"> <div align="center"><font size="+2" color="#FFFFFF">ชื่อ</font></div></th>
<th width="157" bgcolor="#666666"> <div align="center"><font size="+2" color="#FFFFFF">นามสกุล</font></div></th>
<th width="157" bgcolor="#666666"> <div align="center"><font size="+2" color="#FFFFFF">ที่อยู่</font></div></th>
<th width="131" bgcolor="#666666"> <div align="center"><font size="+2" color="#FFFFFF">เบอร์โทรศัพท์</font></div></th>
<th width="162" bgcolor="#666666"> <div align="center"><font size="+2" color="#FFFFFF">ตำแหน่ง</font></div></th>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
<tr>
<td height="25" align="center" bgcolor="#CCCCCC"><font size="5" color="#FFFFFF">
<?=$objResult["staff_id"];?>
</font></td>
<td align="center" bgcolor="#CCCCCC"><font size="5" color="#FFFFFF">
<?=$objResult["staff_name"];?>
</font></td>
<td align="center" bgcolor="#CCCCCC"><font size="5" color="#FFFFFF">
<?=$objResult["staff_sername"];?>
</font></td>
<td align="center" bgcolor="#CCCCCC"><font size="5" color="#FFFFFF">
<?=$objResult["address"];?>
</font></td>
<td align="center" bgcolor="#CCCCCC"><font size="5" color="#FFFFFF">
<?=$objResult["tel1"];?>
</font></td>
<td align="center" bgcolor="#CCCCCC"><font size="5" color="#FFFFFF">
<?=$objResult["position"];?>
</font></td>
</tr>
<?
}
?>
</table>
<font size="+2" color="#333333"><br />
</font>
<table width="897" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<th width="897" align="left" scope="row"><font size="+1" color="#333333">
ข้อมูลทั้งหมด |<?= $num_records;?>| รายการ : <?=$Num_Pages;?> หน้า :
<?
if($Prev_Page)
{
echo "<< <a href=\"JavaScript:doCallAjax(document.getElementById('txtSearch').value,'$Prev_Page')\">กลับ</a> ";
}
for($i=1; $i<=$Num_Pages; $i++)
{
if($i != $Page)
{
echo "[ <a href=\"JavaScript:doCallAjax(document.getElementById('txtSearch').value,'$i')\">$i</a> ]";
}
else
{
echo "<b> $i </b>";
}
}
if($Page!=$Num_Pages)
{
echo " <a href=\"JavaScript:doCallAjax(document.getElementById('txtSearch').value,'$Next_Page')\">ถัดไป</a> >> ";
}
?></font>
</p></th>
</tr>
</table></td>
</tr>
</table>
<p>
<?
mysql_close();
?>
</form>
</body>
</html>
|
|
|
|
|
Date :
2014-07-13 23:16:50 |
By :
pklangkua |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|