|
|
|
(PHP)Search Record เป็นภาษาไทยไม่ได้ รบกวนช่วยดูทีครับ |
|
|
|
|
|
|
|
ทำการพิมข้อมูลลงในช่องข้อมูลเป็นภาษา อังกฤษหรือตัวเลขก็ค้นหาได้แต่ พอพิมภาษาไทยไป ก็พังเลย รบกวนแนะนำทีครับ
Code (PHP)
employeelist.php
<?php
session_start();
require('Core.php');
$obj = new Core;
if(!isset($_SESSION['POS_ID']) && !isset($_SESSION['EMP_ID']))
{
echo "<script language='javascript'> alert('No Session ');window.location='main_page.php';</script>";
}
$sql = "SELECT * FROM employee,position,position_roles,roles
WHERE position.POS_ID = '".$_SESSION['POS_ID']."' and employee.EMP_ID ='".$_SESSION['EMP_ID']."' and position_roles.ROLE_ID = 'ROLE001'
and employee.POS_ID = position.POS_ID and position.POS_ID = position_roles.POS_ID and roles.ROLE_ID = position_roles.ROLE_ID";
$obj->query($sql);
$num = $obj->num_rows();
if(!$num)
{
header("Location:main_page.php");
}
if(!isset($_SESSION['EMP_ID']))
{
echo "<script language='javascript'> alert('Please Login');window.location='index.php';</script>";
}
//*** Get User Login
$strSQL = "SELECT * FROM employee em,position pos WHERE em.EMP_ID = '".$_SESSION['EMP_ID']."' and em.POS_ID = pos.POS_ID ";
$obj->query($strSQL);
$objResult1 = $obj->fetch_assoc();
$strSQL = "SELECT LPAD(SUBSTR(MAX(EMP_ID),4,4)+1,4,'0') FROM employee";
$obj->query($strSQL);
$objResult = $obj->fetch_array();
if($objResult[0] != NULL)
{
$result = "EMP".$objResult[0];
}else
{
$result = 'EMP0001';
}
?>
<!DOCTYPE html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="css/templatemo_main.css">
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/Chart.min.js"></script>
<script src="js/templatemo_script.js"></script>
<script src="function_page/function_employee.js"></script>
<title>Employee</title>
</head>
<body>
<div class="navbar navbar-inverse" role="navigation">
<div class="navbar-header">
<div class="logo"><h1>Intrend Music Guitar Shop</h1></div>
</div>
</div>
<div class="template-page-wrapper">
<?php include'menu.php'; ?> <!-- Load Menu-->
<div class="templatemo-content-wrapper">
<div class="templatemo-content">
<?php
if(isset($_POST['submit']))
{
$sqls = "SELECT * FROM employee WHERE EMP_USER = '".$_POST['user']."' ";
$obj->query($sqls);
$objResult = $obj->fetch_array();
if($objResult['EMP_USER'])
{
echo "<script language='javascript'>alert('Username is Exist');window.location='employee.php';</script>";
}
else
{
if($_POST['pass1'] == $_POST['pass2'] )
{
$sql = "INSERT INTO employee (EMP_ID,EMP_NAME,EMP_LNAME,EMP_SEX,EMP_IDCARD,EMP_ADDRESS,EMP_USER,EMP_PASS,EMP_EMAIL,EMP_SDATE,EMP_BDATE,EMP_STATUS,EMP_SALARY,POS_ID,PV_ID,flagdel)
VALUES ('".$_POST['id']."','".$_POST['fname']."','".$_POST['lname']."','".$_POST['sex']."','".$_POST['idcard']."','".$_POST['address']."'
,'".$_POST['user']."','".$_POST['pass1']."','".$_POST['email']."','".$_POST['sdate']."','".$_POST['bdate']."',0,'".$_POST['salary']."','".$_POST['posid']."','".$_POST['proid']."','0' )";
$Objresult = $obj->query($sql);
for ($i=0; $i<sizeof($_POST['Phone']); $i++)
{
$sqlphone = "INSERT INTO employee_telephone (EMP_TEL,EMP_ID) VALUES ('".$_POST['Phone'][$i]."','".$_POST['id']."')";
$resulphone = $obj->query($sqlphone);
}
echo "<script language='javascript'>window.location='employee.php';</script>";
}
else
{
echo "<script language='javascript'>alert('Password is not Math');</script>";
}
}
}
?>
<div class="row">
<div class="col-md-6">
<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
</div>
</form>
<?php
$obj->query("SELECT * FROM employee WHERE flagdel = 0");
?>
<div class="col-md-12 col-sm-6 margin-bottom-30">
<!-- <div class="panel panel-primary">
<div class="panel-heading">ข้อมูลพนักงาน</div> -->
<table width="100%" >
<tr>
<td width="25%">
<div align="right">ค้นหา : </div>
</td>
<td width="55%">
<input name="txtSearch" id="txtSearch" type="text" size="30" value="">
<button type="button" onClick="location.href='employeelist.php'" >Search</button>
</td>
<td width="10%"><div align="left"><button type="button" onClick="location.href='employee.php'" >เพิ่มพนักงาน</button></div></td>
</tr>
</table>
<div class="panel-body">
<table class="table table-striped" id="myTable" width="100%">
<thead>
<tr>
<th width="11%">รหัสพนักงาน</th>
<th width="13%">ชื่อ-นามสกุล</th>
<th>เพศ</th>
<th>รหัสผู้ใช้</th>
<th>รหัสผ่าน</th>
<th width="18%">หมายเลขบัตรประชาชน</th>
<th>อีเมล์</th>
<th width="20%">ที่อยู่</th>
<th>แก้ไข</th>
<th>ลบ</th>
</tr>
</thead>
<tbody>
<?php
$i =0;
while ($rows = $obj->fetch_array())
{
?>
<tr>
<td><?php echo $rows['EMP_ID']?></td>
<td><?php echo $rows['EMP_NAME'] .' '.$rows['EMP_LNAME'] ?></td>
<?php
if($rows['EMP_SEX'] =='M')
{
$sex = $rows['EMP_SEX'] = "ชาย";
?>
<td><?php echo $sex ?></td>
<?php }
else
{
$sex = $rows['EMP_SEX'] = "หญิง";
?>
<td><?php echo $sex ?></td>
<?php }
?>
<td><?php echo $rows['EMP_USER']?></td>
<td><?php echo $rows['EMP_PASS']?></td>
<td><?php echo $rows['EMP_IDCARD']?></td>
<td><?php echo $rows['EMP_EMAIL']?></td>
<td><?php echo $rows['EMP_ADDRESS']?></td>
<td><a id="add'<?php echo $i;?>'" href="EditEmployee.php?EMP_ID=<?php echo $rows['EMP_ID']?>"><img src=images/edit.png></a></td>
<td><a id="delete'<?php echo $i;?>'" href="DeleteEmployee.php?EMP_ID=<?php echo $rows['EMP_ID']?>"><img src=images/delete-16.gif></a></td>
</tr>
<?php } ?>
</tbody>
</table>
<button type="button" onClick="location.href='main_page.php'" >ยกเลิก</button>
</div>
</div>
<!-- </div>
</div> -->
<!-- Modal -->
<div class="modal fade" id="confirmModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title" id="myModalLabel">Are you sure you want to sign out?</h4>
</div>
<div class="modal-footer">
<a href="logout.php" class="btn btn-primary">Yes</a>
<button type="button" class="btn btn-default" data-dismiss="modal">No</button>
</div>
</div>
</div>
</div>
</body>
</html>
Function_employee.js
Code (JavaScript)
$(document).ready(function() {
$('#txtSearch').click(function(){
$('#txtSearch').removeClass('txtSearch');
});
$('#txtSearch').keyup(function(){
var txtSearch=$('#txtSearch').val();
var dataString = 'txtSearch='+ txtSearch;
if(txtSearch==''){}
else{
$.ajax({ type: "POST",
url: "SearchEmployee.php",
data: dataString,
cache: false,
success: function(html)
{
$('#myTable').html(html).show();
}
});
return false;
}
return false;
});
});
SearchEmployee.php
Code (PHP)
<?php
header("Content-type:text/html; charset=UTF-8");
require('Core.php');
$obj = new Core;
$txtSearch=$_POST['txtSearch'];
if($txtSearch !="")
{
$sql = "SELECT * FROM employee WHERE employee.flagdel = 0
and (employee.EMP_ID like '%$txtSearch%' or employee.EMP_NAME like '%$txtSearch%' or employee.EMP_LNAME like '%$txtSearch%'
or employee.EMP_IDCARD like '%$txtSearch%'or employee.EMP_SEX like '%$txtSearch%' or employee.EMP_ADDRESS like '%$txtSearch%'
or employee.EMP_USER like '%$txtSearch%' or employee.EMP_PASS like '%$txtSearch%' or employee.EMP_EMAIL like '%$txtSearch%'
or employee.EMP_SDATE like '%$txtSearch%' or employee.EMP_STATUS like '%$txtSearch%' or employee.EMP_SALARY like '%$txtSearch%'
or employee.EMP_BDATE like '%$txtSearch%') ORDER BY EMP_ID";
}
$obj->query($sql);
$rows = $obj->num_rows();
echo var_dump($rows);
// if($rows>0){
$HTML="";
$i =0;
echo "<table class='table table-striped' width='100%'>
<tr>
<th width='11%'>รหัสพนักงาน</th>
<th width='13%'>ชื่อ-นามสกุล</th>
<th>เพศ</th>
<th>รหัสผู้ใช้</th>
<th>รหัสผ่าน</th>
<th width='18%''>หมายเลขบัตรประชาชน</th>
<th>อีเมล์</th>
<th width='20%'>ที่อยู่</th>
<th>แก้ไข</th>ด
<th>ลบ</th>
</tr>";
while($row = $obj->fetch_array()){
echo "<tr>";
echo "<td>" .$row['EMP_ID'] . "</td>";
echo "<td>" . $row['EMP_NAME'] .' '.$row['EMP_LNAME'] ."</td>";
if($row['EMP_SEX'] =='M')
{
$sex = $row['EMP_SEX'] ='ชาย';
echo "<td>" . $sex . "</td>";
}else
{
$sex = $row['EMP_SEX'] ='หญิง';
echo "<td>" . $sex . "</td>";
}
echo "<td>" . $row['EMP_USER'] . "</td>";
echo "<td>" . $row['EMP_PASS'] . "</td>";
echo "<td>" . $row['EMP_IDCARD'] . "</td>";
echo "<td>" . $row['EMP_EMAIL'] . "</td>";
echo "<td>" . $row['EMP_ADDRESS'] . "</td>";
// echo "<td>" .'<input type="checkbox" name="select[]" ' .' value ="'. $row['PRO_ID'] .'" >'. "</td>";
echo "<td>" . '<a id="add'.$i.'" class="various iframe" href="EditEmployee.php?EMP_ID='.$row['EMP_ID'].'"><img src=images/edit.png></a>'. "</td>";
echo "<td>" . '<a id="delete'.$i.'" class="various iframe" href="DeleteEmployee.php?EMP_ID='.$row['EMP_ID'].'"><img src=images/delete-16.gif></a>'. "</td>";
echo "</tr>";
}
echo "</table>";
echo $HTML;
// }
?>
Tag : PHP, JavaScript, Ajax, jQuery
|
|
|
|
|
|
Date :
2015-02-13 18:11:42 |
By :
top113457 |
View :
909 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ได้แล้วนะครับ
|
|
|
|
|
Date :
2015-02-13 18:18:09 |
By :
top113457 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|