|
|
|
สืบเนื่องจาก PHP MySQL Add/Insert/Edit/Delete to MySQL On Same Form |
|
|
|
|
|
|
|
โอ๊ะ โอะ ทำได้แล้วค่ะ ต้องแทนค่าตัวแปรส่งไปด้วย แต่ส่งผิดตัว ผิดที่ มันเลยไม่ออก
|
|
|
|
|
Date :
2012-10-19 14:17:12 |
By :
keewa |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date :
2012-10-20 08:21:24 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<?php session_start();
include("../config/config_db.php");
$login = $_SESSION['login'];
$conn = mysql_connect($dbhost,$dbuser,$dbpass) or die(mysql_error());
$db = mysql_select_db($dbname) or die(mysql_error());
mysql_query("SET NAMES UTF8");
$sql = "select * from tbank_admin where office_id = '$login'";
$query = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($query);
?>
<!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>New Appointment</title>
<style type="text/css">
<!--
body,td,th {
font-family: Tahoma, Geneva, sans-serif;
font-size: 12px;
}
a:link {
color: #36F;
}
a:visited {
color: #36F;
}
a:hover {
color: #36F;
}
a:active {
color: #36F;
}
.font_comment {
font-family: Tahoma, Geneva, sans-serif;
font-size: 12px;
color: #F00;
}
-->
body, th, td, input, textarea, select {
line-height: 16px;
font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif;
font-size: 13px;
color: #3F3F3F;
}
</style>
<!-- link calendar files -->
<script language="JavaScript" src="calendar_eu.js"></script>
<link rel="stylesheet" href="calendar.css">
</head>
<body>
<?
//*** Update Condition ***//
if($_POST["hdnCmd"] == "Update"){
$strSQL = "UPDATE tbank_domicile_marketing SET ";
$strSQL .="office_id = '".$_POST["txtEditOfficeID"]."' ";
$strSQL .=",password = '".$_POST["txtEditPassword"]."' ";
$strSQL .=",ao_full_name = '".$_POST["txtEditAoFullName"]."' ";
$strSQL .=",ao_eng_name = '".$_POST["txtEditAoEngName"]."' ";
$strSQL .=",branch_code = '".$_POST["txtEditBranchCode"]."' ";
$strSQL .=",branch_name = '".$_POST["txtEditBranchName"]."' ";
$strSQL .=",position = '".$_POST["txtEditPosition"]."' ";
$strSQL .=",level = '".$_POST["txtEditLevel"]."' ";
$strSQL .=",limit_value = '".$_POST["txtEditLimitValue"]."' ";
$strSQL .=",current_status = '".$_POST["txtEditCurrentStatus"]."' ";
$strSQL .="WHERE office_id = '".$_POST["hdnEditOfficeID"]."' ";
$objQuery = mysql_query($strSQL);
if(!$objQuery){
echo "Error Update [".mysql_error()."]";
}
//header("location:$_SERVER[PHP_SELF]");
//exit();
}
//*** Delete Condition ***//
if($_GET["Action"] == "Del")
{
$strSQL = "DELETE FROM tbank_domicile_marketing ";
$strSQL .="WHERE office_id = '".$_GET["office_id"]."' ";
$objQuery = mysql_query($strSQL);
if(!$objQuery){
echo "Error Delete [".mysql_error()."]";
}
//header("location:$_SERVER[PHP_SELF]");
//exit();
}
if($_GET["txtKeyword"] != ""){
$strSQL = "SELECT * FROM tbank_domicile_marketing
WHERE office_id LIKE '%".$_GET["txtKeyword"]."%'
OR password LIKE '%".$_GET["txtKeyword"]."%'
OR ao_full_name LIKE '%".$_GET["txtKeyword"]."%'
OR ao_eng_name LIKE '%".$_GET["txtKeyword"]."%'
OR branch_code LIKE '%".$_GET["txtKeyword"]."%'
OR branch_name LIKE '%".$_GET["txtKeyword"]."%'
OR position LIKE '%".$_GET["txtKeyword"]."%'
OR level LIKE '%".$_GET["txtKeyword"]."%'
OR limit_value LIKE '%".$_GET["txtKeyword"]."%'
OR current_status LIKE '%".$_GET["txtKeyword"]."%' ";
}else{
$strSQL = "SELECT * FROM tbank_domicile_marketing ";
}
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$Num_Rows = mysql_num_rows($objQuery);
?>
<form name="frmMain" method="post" action="<?=$_SERVER['SCRIPT_NAME'];?>">
<input type="hidden" name="hdnCmd" value="">
<table width="916" border="0" align="center" cellpadding="2" cellspacing="2">
<tr>
<td colspan="4"><img src="../images/manage_report.jpg" alt="" width="916" height="64" border="0" usemap="#Map" /></td>
</tr>
<tr>
<td colspan="4"> </td>
</tr>
<tr>
<td width="474">You are here : <a href="admin_login.php">Admin_Login</a>/<a href="#">Upload Report</a></td>
<td width="352" align="right"><?php
echo "Username : ". $row['office_id']." ";
echo " ".$row['admin_full_name']." ";
$_SESSION['login'] = $login;
$office_id = $row['office_id'];
$admin_full_name = $row['admin_full_name'];
$_SESSION['office_id'] = $office_id;
$_SESSION['admin_full_name'] = $admin_full_name;
?>
</td>
<td colspan="2" align="right"><a href="../logout.php"><img src="../images/pic_logout.jpg" alt="" width="77" height="23" border="0" /></a></td>
</tr>
<tr>
<td> </td>
<td align="right"> </td>
<td colspan="2" align="right"> </td>
</tr>
<tr>
</tr>
<tr>
<td colspan="4" align="center"> </td>
</tr>
<tr>
<td colspan="4" align="center"> </td>
</tr>
<tr>
<td colspan="4">
<input name="txtKeyword" type="text" id="txtKeyword" value="<?=$_GET["txtKeyword"];?>" />
<input type="submit" value="Search" /></td>
</tr>
<tr>
<td colspan="4">
<?php
// Logic ในการแบ่งหน้าจอ
$Per_Page = 30; // ตั้งค่าว่า 1 หน้าให้มีกี่รายการ
$Page = $_GET["Page"];
if(!$_GET["Page"])
{
$Page=1;
}
$Prev_Page = $Page-1;
$Next_Page = $Page+1;
$Page_Start = (($Per_Page*$Page)-$Per_Page);
if($Num_Rows<=$Per_Page)
{
$Num_Pages =1;
}
else if(($Num_Rows % $Per_Page)==0)
{
$Num_Pages =($Num_Rows/$Per_Page) ;
}
else
{
$Num_Pages =($Num_Rows/$Per_Page)+1;
$Num_Pages = (int)$Num_Pages;
}
$strSort = $_GET["sort"];
if($strSort == "")
{
//column to order
$strSort = "office_id";
$strSort = "ao_full_name";
$strSort = 'ao_eng_name';
$strSort = 'branch_code';
$strSort = 'branch_name';
$strSort = 'position';
$strSort = 'level';
$strSort = 'limit_value';
$strSort = 'current_status';
}
$strOrder = $_GET["order"];
if($strOrder == "")
{
$strOrder = "DESC";
}
$strSQL .=" ORDER BY ".$strSort." ".$strOrder." LIMIT $Page_Start , $Per_Page";
$objQuery = mysql_query($strSQL);
$strNewOrder = $strOrder == 'DESC' ? 'ASC' : 'DESC';
?>
<table width="100%" border="0" align="center">
<tr>
<th> </th>
<th> </th>
<th> </th>
<th> </th>
<th> </th>
<th> </th>
<th> </th>
<th> </th>
<th> </th>
<th> </th>
<th> </th>
</tr>
<tr>
<th> </th>
<th> </th>
<th> </th>
<th> </th>
<th> </th>
<th> </th>
<th> </th>
<th> </th>
<th> </th>
<th> </th>
<th> </th>
</tr>
<tr>
<th width="50" bgcolor="#F77306"> <div align="center"><a href="<?=$_SERVER["PHP_SELF"];?>?sort=office_id&order=<?=$strNewOrder?>">OFFICE ID</a></div></th>
<th width="50" bgcolor="#F77306"> <div align="center"><a href="<?=$_SERVER["PHP_SELF"];?>?sort=password&order=<?=$strNewOrder?>">PASSWORD</a></div></th>
<th width="120" bgcolor="#F77306"> <div align="center"><a href="<?=$_SERVER["PHP_SELF"];?>?sort=ao_full_name&order=<?=$strNewOrder?>">THAI NAME</a></div></th>
<th width="80" bgcolor="#F77306"> <div align="center"><a href="<?=$_SERVER["PHP_SELF"];?>?sort=ao_eng_name&order=<?=$strNewOrder?>">ENG NAME</a></div></th>
<th width="50" bgcolor="#F77306"> <div align="center"><a href="<?=$_SERVER["PHP_SELF"];?>?sort=branch_code&order=<?=$strNewOrder?>">BRANCH CODE</a></div></th>
<th width="80" bgcolor="#F77306"> <div align="center"><a href="<?=$_SERVER["PHP_SELF"];?>?sort=branch_name&order=<?=$strNewOrder?>">BRANCH NAME</a></div></th>
<th width="50" bgcolor="#F77306"> <div align="center"><a href="<?=$_SERVER["PHP_SELF"];?>?sort=position&order=<?=$strNewOrder?>">POSITION</a></div></th>
<th width="25" align="left" bgcolor="#F77306"> <div align="center"><a href="<?=$_SERVER["PHP_SELF"];?>?sort=level&order=<?=$strNewOrder?>">LEVEL</a></div></th>
<th width="25" align="left" bgcolor="#F77306"> <div align="center"><a href="<?=$_SERVER["PHP_SELF"];?>?sort=current_status&order=<?=$strNewOrder?>">STATUS</a></div></th>
<th width="40" bgcolor="#F77306"> <div align="center">EDIT</div></th>
<th width="40" bgcolor="#F77306"> <div align="center">DELETE</div></th>
</tr>
<?php
//โชว์ข้อมูลและสลับสีแถว
$i=0;
while($objResult = mysql_fetch_array($objQuery)){
$i++;
if($i%2==0){
$bg = "#CCCCCC";
}else{
$bg = "#EEEDE9";
}
if($objResult["office_id"] == $_GET["office_id"] and $_GET["Action"] == "Edit"){
?>
<tr>
<td bgcolor="<?=$bg?>"><div align="center">
<input name="txtEditOfficeID" type="text" readonly="readonly" value="<?=$objResult["office_id"];?>" size="8" >
<input type="hidden" name="hdnEditOfficeID" size="5" value="<?=$objResult["office_id"];?>"></div></td>
<td bgcolor="<?=$bg?>"><input type="text" name="txtEditPassword" size="10" value="<?=$objResult["password"];?>"></td>
<td bgcolor="<?=$bg?>"><input type="text" name="txtEditAoFullName" size="20" value="<?=$objResult["ao_full_name"];?>"></td>
<td align="left" bgcolor="<?=$bg?>"><input name="txtEditAoEngName" type="text"
value="<?=$objResult["ao_eng_name"];?>" size="15"></td>
<td bgcolor="<?=$bg?>"><input type="text" name="txtEditBranchCode" size="5" value="<?=$objResult["branch_code"];?>"></td>
<td bgcolor="<?=$bg?>"><input type="text" name="txtEditBranchName" size="15" value="<?=$objResult["branch_name"];?>"></td>
<td align="left" bgcolor="<?=$bg?>"><input name="txtEditPosition" type="text"
value="<?=$objResult["position"];?>" size="15"></td>
<td align="left" bgcolor="<?=$bg?>"><input name="txtEditLevel" type="text"
value="<?=$objResult["level"];?>" size="2"></td>
<td align="left" bgcolor="<?=$bg?>"><input name="txtEditCurrentStatus" type="text"
value="<?=$objResult["current_status"];?>" size="2"></td>
<td colspan="2" align="right" bgcolor="<?=$bg?>"><div align="center">
<input name="btnAdd" type="button" id="btnUpdate" value="Update" OnClick="frmMain.hdnCmd.value='Update';frmMain.submit();">
<input name="btnAdd" type="button" id="btnCancel" value="Cancel" OnClick="window.location='<?=$_SERVER["PHP_SELF"];?>';">
</div></td>
</tr>
<?
}else{
?>
<tr>
<td bgcolor="<?=$bg?>"><div align="left"><?=$objResult["office_id"];?></div></td>
<td bgcolor="<?=$bg?>" align="left"><?=$objResult["password"];?></td>
<td bgcolor="<?=$bg?>" align="left"><?=$objResult["ao_full_name"];?></td>
<td align="left" bgcolor="<?=$bg?>"><div align="left"><?=$objResult["ao_eng_name"];?></div></td>
<td bgcolor="<?=$bg?>" align="center"><?=$objResult["branch_code"];?></td>
<td bgcolor="<?=$bg?>" align="left"><?=$objResult["branch_name"];?></td>
<td align="left" bgcolor="<?=$bg?>"><div align="left"><?=$objResult["position"];?></div></td>
<td align="left" bgcolor="<?=$bg?>"><div align="center"><?=$objResult["level"];?></div></td>
<td align="left" bgcolor="<?=$bg?>"><div align="center"><?=$objResult["current_status"];?></div></td>
<td align="center" bgcolor="<?=$bg?>"><a href="<?=$_SERVER["PHP_SELF"];?>?Action=Edit&office_id=<?=$objResult["office_id"];?>">Edit</a></td>
<td align="center" bgcolor="<?=$bg?>"><a href="JavaScript:if(confirm('Confirm Delete?')==true){window.location='<?=$_SERVER["PHP_SELF"];?>?Action=Del&office_id=<?=$objResult["office_id"];?>';}">Delete</a></td>
</tr>
<?php } ?>
<?php } ?>
</table>
</td>
</tr>
<tr>
<td colspan="4" align="center"> </td>
</tr>
<tr>
<td colspan="4" align="center"><strong>Total <?= $Num_Rows;?> Record : <?=$Num_Pages;?> Page : </strong>
<?
if($Prev_Page)
{
echo " <a href='$_SERVER[PHP_SELF]?Page=$Prev_Page&sort=$strSort&txtKeyword=$_GET[txtKeyword]'><< Back</a> ";
}
for($i=1; $i<=$Num_Pages; $i++){
if($i != $Page)
{
echo "[ <a href='$_SERVER[PHP_SELF]?Page=$i&sort=$strSort&txtKeyword=$_GET[txtKeyword]'>$i</a> ]";
}
else
{
echo "<b> $i </b>";
}
}
if($Page!=$Num_Pages)
{
echo " <a href ='$_SERVER[PHP_SELF]?Page=$Next_Page&sort=$strSort&txtKeyword=$_GET[txtKeyword]'>Next>></a> ";
}
mysql_close($conn);
?>
</td>
</tr>
</table>
<p> </p>
</form>
<map name="Map" id="Map">
<area shape="rect" coords="110,44,196,67" href="change_ao_owner.php" />
</map>
</body>
</html>
|
|
|
|
|
Date :
2012-10-22 19:19:18 |
By :
Christopher |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|