|
|
|
ขอความช่วยเหลือคะ มีปัญหาการเเก้ไขข้อมูลในฟอร์มเดิม มีการ refrechหน้า |
|
|
|
|
|
|
|
Code (PHP)
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Creative - Bootstrap 3 Responsive Admin Template">
<meta name="author" content="GeeksLabs">
<meta name="keyword" content="Creative, Dashboard, Admin, Template, Theme, Bootstrap, Responsive, Retina, Minimal">
<link rel="shortcut icon" href="img/favicon.png">
<!-- //////// -->
<!--
<script type="text/javascript">
$(document).ready(function() {
$('#example').DataTable();
} );
</script> -->
<?php
include ("sidebar.php");
include ("connect.php");
// ประกาศค่าตัวแปรส่งค่ากลับ
if(isset($_GET["id"])){
$pickmat_id =$_GET["id"];
}else{
$pickmat_id ="";
}
$test_id = "select MAX(SUBSTRING(detail_pickmat_id,4)) as num from detail_pick_material ";
$tmp = mysql_query($test_id) or die (mysql_error()." Error Query [". $test_id."]");
mysql_query("SET NAMES UTF8");
$rows = mysql_fetch_array($tmp);
// สร้างรหัสรายละเอียด
if($rows){
$num = $rows['num'];
if($num==Null){
$num = 0;
}
$test_id = $num+1;
if($test_id < 10){
$detail_pickmat_id = "DPM00".$test_id;
}
elseif ($test_id < 100) {
$detail_pickmat_id = "DPM0".$test_id;
}
elseif ($test_id < 1000) {
$detail_pickmat_id = "DPM".$test_id;
}
}
// ประกาศค่าตัวแปร
$detail_pickmat_ids=$detail_pickmat_id;
if(isset($_GET["detail_pickmat_id"])){
$detail_pickmat_id=$_GET["detail_pickmat_id"];
}else{
$detail_pickmat_id="";
}
if(isset($_GET["Action"])){
$Action=$_GET["Action"];
}else{
$Action="";
}
if(isset($_POST["hdnCmd"])){
$hdnCmd=$_POST["hdnCmd"];
}else{
$hdnCmd="";
}
//*** Add Condition ***//
if($hdnCmd == "Add")
{
$strSQL = "INSERT INTO detail_pick_material ";
$strSQL .="(detail_pickmat_id,pickmat_id,mat_id,amount_pick) ";
$strSQL .="VALUES";
$strSQL .="('".$_POST["detail_pickmat_id"]."'";
$strSQL .=",'".$_POST["pickmat_id"]."'";
$strSQL .=",'".$_POST["material"]."'";
$strSQL .=",'".$_POST["amount_pick"]."') ";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
echo "Error Save [".mysql_error()."]";
}
}
//*** Update Condition ***//
if($hdnCmd == "Update")
{
$strSQL = "UPDATE detail_pick_material SET ";
$strSQL .="detail_pickmat_id = '".$_POST["detail_pickmat_id"]."' ";
$strSQL .=",amount_pick = '".$_POST["amount_pick"]."' ";
$strSQL .="WHERE detail_pickmat_id = '".$_POST["detail_pickmat_id"]."' ";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
echo "Error Update [".mysql_error()."]";
}
//header("location:$_SERVER[PHP_SELF]?id=<?php //echo $detail_pickmat_id;?;");
// exit();
}
//*** Delete Condition ***//
if($Action == "Del")
{
$strSQL = "DELETE FROM detail_pick_material ";
$strSQL .="WHERE detail_pickmat_id = '".$_GET["detail_pickmat_id"]."' ";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
echo "Error Delete [".mysql_error()."]";
}
//header("location:$_SERVER[PHP_SELF]");
//exit();
}
?>
<section id="main-content"> <!-- อย่าลบเลย -->
<section class="wrapper"> <!-- อย่าลบเลย -->
<!--overview start-->
<div class="row">
<div class="col-lg-12">
<?php
//แบ่งหน้า
$result = mysql_query("SELECT count(*) FROM detail_pick_material WHERE pickmat_id = '".$pickmat_id."' ORDER BY detail_pickmat_id ") or die(mysql_error());
$total_rec=mysql_result($result,0,0);
$p_size=10;
$total_page=(int)($total_rec/$p_size);
if(($total_rec % $p_size)!=0){
$total_page++;
}
if(empty($_GET['page'])){
$page=1;
$start=0;
}else{
$page=$_GET['page'];
$start=$p_size*($page-1);
}
$begin = ($page*$p_size)-$p_size;
$offset = ($page*$p_size)/$page;
// $strSQL = "SELECT * FROM detail_pick_material";
$strSQL = "select dp.detail_pickmat_id, p.pickmat_id, m.mat_name, amount_pick, unit_name from detail_pick_material dp join pick_material p join material m join unit u where dp.mat_id = m.mat_id and m.unit_id = u.unit_id and p.pickmat_id = dp.pickmat_id and dp.pickmat_id = '".$pickmat_id."' order by detail_pickmat_id DESC LIMIT $offset OFFSET $begin ";//
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<form name="frmMain" method="post" action="<?php echo $_SERVER["PHP_SELF"];?>?id=<?php echo $pickmat_id ;?>">
<input type="hidden" name="hdnCmd" value="">
<table border="0" width="1005">
<tr>
<td width="880" colspan="5"><h3 class="page-header"><i class="fa fa-laptop"></i> ข้อมูลการเบิกวัสดุ</h3> </td>
<td width="130">รหัสการเบิกวัสดุที่ : </td>
<!-- <td> </td> -->
<td width="150" colspan="2"><input type="" class="form-control" name="pickmat_id" size="20" value="<?=$pickmat_id; ?>" readonly="readonly"></td>
<input type="hidden" class="form-control" name="pickmat_id" size="20" value="<?=$pickmat_id; ?>" readonly="readonly">
<tr>
</table>
<table border="0" width="1005">
<td width="45px"></td>
<td colspan="7"><h4>เพิ่มรายการวัสดุ</h4></td>
<input type="hidden" class="form-control" name="detail_pickmat_id" size="20" value="<?=$detail_pickmat_ids; ?>" readonly="readonly">
</tr>
<tr>
<td></td>
<td width="120px" align="right">ประเภทวัสดุ : </td>
<td width="200px"> <span id="type_material">
<select class="form-control">
<option value="0"> เลือกประเภทวัสดุ </option>
</select>
</span>
</td>
<td width="120px" align="right">รายการวัสดุ : </td>
<td width="200px">
<span id="material">
<select class="form-control" name="material">
<option value='0'>เลือกวัสดุ</option>
</select>
</span>
</td>
<td width="80px" align="right">จำนวน : </td>
<td width="70px"><input type="text" class="form-control" name="amount_pick" width="30px"></td>
<td align="center"><input name="btnAdd" type="button" id="btnAdd" value="+" class="btn btn-success pull-center" OnClick="frmMain.hdnCmd.value='Add';frmMain.submit();"></td>
</tr>
</table>
<br>
<div class="panel panel-default">
<div class="panel-body">
<table id='table1' class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th align="center">#</th>
<th align="center">รายการวัสดุ</th>
<th align="center">จำนวน</th>
<th align="center">หน่วยนับ</th>
<th align="center">การจัดการ</th>
</tr>
</thead>
<tbody>
<?php
$x=1;
if($page > 1)
{
$x = ($p_size*($page-1)) + 1;
}
while($objResult = mysql_fetch_array($objQuery))
{
?>
<?php
if($objResult["detail_pickmat_id"] == $detail_pickmat_id and $Action == "Edit")
{
?>
<tr>
<td><div align="center"><?php echo $x++;?></div></td>
<td><div align="center">
<input type="hidden" name="detail_pickmat_id" size="5" value="<?php echo $objResult["detail_pickmat_id"];?>">
<?php echo $objResult["mat_name"];?>
</div></td>
<td><input type="" name="amount_pick" size="5" value="<?php echo $objResult["amount_pick"];?>"></td>
<td><?php echo $objResult["unit_name"];?></td>
<td colspan="2" align="right"><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='<?php echo $_SERVER["PHP_SELF"];?>?id=<?php echo $pickmat_id;?>';">
</div></td>
</tr>
<?php
}
else
{
?>
<tr>
<td><div align="center"><?php echo $x++;?></div></td>
<td><div align="center"><?php echo $objResult["mat_name"];?></div></td><!-- &pickmat_id=<?php echo $pickmat_id;?> -&page=".$i.">&page=<?php echo $pages;?> -->
<td><?php echo $objResult["amount_pick"];?></td>
<!-- <td><?php //echo $objResult["pickmat_id"];?></td> -->
<td><?php echo $objResult["unit_name"];?></td>
<?php //for($i=1;$i<=$total_page;$i++){ ?>
<td align="center"><a href="<?php echo $_SERVER["PHP_SELF"];?>?Action=Edit&detail_pickmat_id=<?php echo $objResult["detail_pickmat_id"];?>&id=<?php echo $pickmat_id;?>" class="btns btn-info" >Edit</a>
<?php ;// } ?>
<a href="JavaScript:if(confirm('ต้องการลบข้อมูล?')==true){window.location='<?php echo $_SERVER["PHP_SELF"];?>?Action=Del&detail_pickmat_id=<?php echo $objResult["detail_pickmat_id"];?>&id=<?php echo $pickmat_id;?>';}" class="btns btn-warning">Delete</a></td>
</tr>
<?php
}
?>
<?php
}
?>
</tbody>
</table>
</div>
</div>
</form>
<table>
<?php
echo'<tr><td><label>ทั้งหมด '.$total_rec.' รายการ</label></td></tr>';
?>
<ul class="pagination pull-right">
<?php
if($total_rec>1){
$back = $total_rec-1;
echo "<li><a href=".$_SERVER['PHP_SELF']."?id=".$pickmat_id."&detail_pickmat_id=".$detail_pickmat_id."&page=".$back.">«</a></li>";//color_name=".$color_name."&
}
else
echo "<li><a>«</a></li>";
?>
<?php
for($i=1;$i<=$total_page;$i++){ //สร้าง Link เพื่อให้ผู้ใช้งานเลือกชมหน้าข้อมูล
echo "<li><a href=".$_SERVER['PHP_SELF']."?id=".$pickmat_id."&detail_pickmat_id=".$detail_pickmat_id."&page=".$i.">".$i."</a></li>";//color_name=".$color_name."&
}
?>
<?php
if($total_rec<$total_page){
$next = $total_rec +1;
echo "<li><a href=".$_SERVER['PHP_SELF']."?id=".$pickmat_id."&detail_pickmat_id=".$detail_pickmat_id."&page=".$next.">»</a></li>";//color_name=".$color_name."&
}
else
echo "<li><a>»</a></li>";
?>
</ul></table>
<?php
// mysql_close($objConnect);
?>
</body>
</div>
</div>
</section><!-- ปิด sectionลองบน -->
</section><!-- ปิด sectionบนสุด -->
<!-- เลือกประเภทวัสดุ -->
<script language=Javascript>
function Inint_AJAX() {
try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {} //IE
try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} //IE
try { return new XMLHttpRequest();} catch(e) {} //Native Javascript
alert("XMLHttpRequest not supported");
return null;
};
function dochange(src, val) {
var req = Inint_AJAX();
req.onreadystatechange = function () {
if (req.readyState==4) {
if (req.status==200) {
document.getElementById(src).innerHTML=req.responseText; //รับค่ากลับมา
}
}
};
req.open("GET", "localtion.php?data="+src+"&val="+val); //สร้าง connection
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8"); // set Header
req.send(null); //ส่งค่า
}
window.onLoad=dochange('type_material', -1);
</script>
เกิดปัญหาในการแก้ไขข้อมูลเมื่อมีการเเก้ไขข้อมูลใน page ที่ 2,3,4 มันจะเด้งมา page ที่1 มันมีการ refrech
มีการประยุกต์ใช้จาก https://www.thaicreate.com/php/forum/114223.html
Tag : PHP, MySQL
|
ประวัติการแก้ไข 2016-07-20 10:52:31
|
|
|
|
|
Date :
2016-07-20 10:04:56 |
By :
POMP |
View :
836 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เพิ่มบรรทัดที่ 101
Code (PHP)
header("location:$_SERVER[PHP_SELF]?page='".$_GET['page']."'");
|
|
|
|
|
Date :
2016-07-20 10:16:29 |
By :
dudesaranyu |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|