Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > ขอคำแนะนำเรื่องการลบข้อมูล พร้อม Update ข้อมูลไปพร้อมๆกันครับ



 

ขอคำแนะนำเรื่องการลบข้อมูล พร้อม Update ข้อมูลไปพร้อมๆกันครับ

 



Topic : 123033



โพสกระทู้ ( 42 )
บทความ ( 0 )



สถานะออฟไลน์




คือ ตอนกดลบต้องทำลบพร้อมกับ update(product_qty) ไปพร้อมๆกัน ทำทั้งสองอย่างใช้คิวรี่สองอันเลย เอาค่าที่ลบมา update
เพราะฉะนั้นก่อนลบต้องไปเอาค่ามาก่อนมาเก็บไว้ก่อนทำไว้เพื่อจะได้รู้ว่าจะต้องลบเท่าไหร่

หลักการ
ตอนกดปุ่มลบทำ 3 อย่าง ดึงค่ามาเก็บไว้ก่อน,ได้ค่าแล้วลบอันนั้นทิ้ง,ค่าที่เก็บมาเอาไป update กับของเดิม

อย่างเช่น
54 (จำนวนสินค้าโคคาโคล่าในหน้า product)
-1 (มีการซื้อไปหนึ่งชิ้น)
=53 (ยอดที่เหลือ)
ไปลบ รายการที่ 97 ที่มี 30 ชิ้น
53-30
=23 (นี่คือยอดจริงๆที่ควรมีอยู่ในproduct สินค้าที่ 1 โคคาโคล่า)

หน้า product
m

หน้า purchase_detail เวลากดลบก็มี update จำนวนที่product_qty หน้า product ทันที
v

ฐานข้อมูล Product
r

ฐานข้อมูล purchase_detail
b

code product.php
Code (PHP)
<?php require_once('Connections/MyConnect.php'); 

  
session_start(); 
mysql_select_db($database_MyConnect, $MyConnect);
$SQL="SELECT * FROM product 
LEFT JOIN category ON (product.cate_id=category.cate_id)
LEFT JOIN unit ON (product.unit_id=unit.unit_id)";

$QUERY= mysql_query($SQL) or die ("Error Query [".$SQL."]".mysql_error());   
		
$sql .= "ORDER BY `product_id` ASC ";

 ?>       
<?php
if (!isset($_SESSION)) {
 
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
  // For security, start by assuming the visitor is NOT authorized. 
  $isValid = False; 

  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  if (!empty($UserName)) { 
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    $arrUsers = Explode(",", $strUsers); 
    $arrGroups = Explode(",", $strGroups); 
    if (in_array($UserName, $arrUsers)) { 
      $isValid = true; 
    } 
    // Or, you may restrict access to only certain users based on their username. 
    if (in_array($UserGroup, $arrGroups)) { 
      $isValid = true; 
    } 
    if (($strUsers == "") && true) { 
      $isValid = true; 
    } 
  } 
  return $isValid; 
}

$MM_restrictGoTo = "admin/index.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0) 
  $MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo); 
  exit;
}
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$maxRows_Productset = 5;
$pageNum_Productset = 0;
if (isset($_GET['pageNum_Productset'])) {
  $pageNum_Productset = $_GET['pageNum_Productset'];
}
$startRow_Productset = $pageNum_Productset * $maxRows_Productset;


$query_Productset = "SELECT * FROM product";
$query_limit_Productset = sprintf("%s LIMIT %d, %d", $query_Productset, $startRow_Productset, $maxRows_Productset);
$Productset = mysql_query($query_limit_Productset, $MyConnect) or die(mysql_error());
$row_Productset = mysql_fetch_assoc($Productset);

if (isset($_GET['totalRows_Productset'])) {
  $totalRows_Productset = $_GET['totalRows_Productset'];
} else {
  $all_Productset = mysql_query($query_Productset);
  $totalRows_Productset = mysql_num_rows($all_Productset);
}
$totalPages_Productset = ceil($totalRows_Productset/$maxRows_Productset)-1;
?>
<!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>Product</title>
<style type="text/css">
#MenuBar1 {
	font-size: 230%;
	font-family: "Courier New", Courier, monospace;
}
body p {
	font-size: 18px;
	text-align: center;
	color: #000;
}
body h2 {
	text-align: center;
}
#form1 #word {
	text-align: left;
}
#form1 #btnSearch {
	text-align: center;
}
#form1 {
	text-align: center;
}
</style>
<script src="js/jquery.js" type="text/javascript"></script>
<link href="css/bootstrap.min.css" rel="stylesheet" type="text/css" />
</head>

<body class='container'>
<p><img src="shop.jpg" width="1117" height="149" />
</p>
<h3>ร้านเกสร
</h3>
<p>ระบบจัดการฐานข้อมูลสำหรับร้านค้าปลีก</p>

<div class="btn-group">
   <button class="btn"><a href="sales_detail.php">ขายสินค้า</a></button>
</div>

<div class="btn-group">
  <button class="btn">ข้อมูลพื้นฐาน</button>
  <button class="btn dropdown-toggle" data-toggle="dropdown">
    <span class="caret"></span>
  </button>  
  <ul class="dropdown-menu">
    <li><a href="Product.php">ข้อมูลสินค้า</a></li>
    <li><a href="Category.php">ข้อมูลประเภทสินค้า</a></li>
    <li><a href="Supplier.php">ข้อมูลผู้จัดจำหน่าย</a></li>
    <!-- dropdown menu links -->
  </ul> 
</div>

<div class="btn-group">
  <button class="btn"><a href="Unit.php">หน่วยสินค้า</a></button>
</div>

<div class="btn-group">
  <button class="btn"><a href="repayment">จัดการลูกหนี้</a></button>
</div>

<div class="btn-group">  
  <button class="btn">เพิ่มเติม</button>
  <button class="btn dropdown-toggle" data-toggle="dropdown">
    <span class="caret"></span>
  </button>  
  <ul class="dropdown-menu">
    <li><a href="#">ดูสินค้าใกล้หมด</a></li>
    <!-- dropdown menu links -->
  </ul>
</div>

  <div class="btn-group">
  <button class="btn"><a href="edit-profile.php">แก้ไขข้อมูลส่วนตัว</a></button>
</div>

  <div class="btn-group">
  <button class="btn"><a href="admin/index.php">ออกจากระบบ</a></button>
</div>
<p>&nbsp;</p>

<form id="form1" name="form1" method="post" action="searchproduct.php">
  <label for="word">ค้นหา:<i class="icon-zoom-in"></i></label>
  <input type="text" name="word" id="word" />
  <input type="submit" name="btnSearch" id="btnSearch" value="ค้นหา" />
</form>
<p>
    <a href="insertproduct.php">
    <input type="submit" name="btn" id="btn" value="เพิ่มสินค้า" /></a></p>
<p>แสดงสินค้า </p>
<?php
if($result["product_qty"] >= 2)
{
  echo "<font color=\"red\">สินค้าหมดแล้ว</font>"; //เราก็เพียงใช้คำสั่ง Font
}
?>
<table class="table table-bordered" width="500" border="1" align="center">
  <tr class="success">
    <td width="159">รหัสสินค้า</td>
    <td width="181">ชื่อสินค้า</td>
    <td width="136">ประเภทสินค้า</td>
    <td width="132">หน่วยสินค้า</td>
    <td width="195">คงเหลือต่ำสุด</td>
    <td width="179">ราคา</td>
    <td width="179">จำนวนสินค้า</td>
    <td width="27">แก้ไข</td>
    <td width="27">ลบ</td>
    <td width="27" align="center">เพิ่มเติม</td>
   </tr>

    <?php 
	while($rs=mysql_fetch_array($QUERY))  {   ?>
    <tr>
      <td><?php echo $rs['product_id']; ?></td>
      <td><?php echo $rs['product_name']; ?></td>
      <td><?php echo $rs['cate_name']; ?></td>
      <td><?php echo $rs['unit_name']; ?></td>
      <td><?php echo $rs['product_balance']; ?></td>
      <td><?php echo $rs['product_price']; ?></td>
      <td><?php echo $rs['product_qty']; ?></td>
      <td><i class="icon-pencil"></i><a href="editproduct.php?product_id=<?php echo $rs['product_id']; ?>">แก้ไข</a></td>
      <td align="center"><i class="icon-trash"></i><a onclick="return confirm_delete()" href="deleteproduct.php?product_id=<?php echo $rs['product_id'];?>">ลบ</a></td>
      <td><i class="icon-asterisk"></i><a href="Purchase_detail.php?product_id=<?php
 echo $rs['product_id']; ?>">เพิ่มเติม</a></td>
    </tr>
    <?php } $rs= mysql_fetch_assoc($Productset); ?>
</table>
<p>
  หน้าที่:
  <?php
for($dw_i=0;$dw_i<=$totalPages_Productset;$dw_i++){
	echo '<a href="?pageNum_Productset=',$dw_i,'"class="pageNum">',($dw_i+1),'</a> ';
}
?>
</p>
<script src="js/jquery.js"></script>
<script src="js/bootstrap.min.js"></script>
<script type="text/javascript">
function confirm_delete() {
  return confirm('ยืนยันการลบข้อมูล !');
}
</script>
<?php
mysql_free_result($Productset);
?>


code Purchase_detail.php
Code (PHP)
<?php require_once('Connections/MyConnect.php'); ?>
<?php require_once('Connections/MyConnect.php'); 

mysql_select_db($database_MyConnect, $MyConnect);
$pd=intval($_REQUEST['product_id']);
$SQL="select 
    pur_detail_id id,
	product_name name,
	DATE_FORMAT(pur_detail_date, '%d-%m-%Y') pur_date,
	pur_detail_principal pur_princ,
	pur_detail_productqty product_qty
from
purchase_detail INNER JOIN product
ON purchase_detail.product_id = product.product_id 
WHERE product.product_id=$pd
";

$QUERY= mysql_query($SQL) or die ("Error Query [".$SQL."]".mysql_error());  

$sql .= "ORDER BY `product_id` ASC ";

 ?>
<?php
if (!isset($_SESSION)) {
   session_start();
}
$MM_authorizedUsers = ""; 
$MM_donotCheckaccess = "true";


// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
  // For security, start by assuming the visitor is NOT authorized. 
  $isValid = False; 

  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  if (!empty($UserName)) { 
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    $arrUsers = Explode(",", $strUsers); 
    $arrGroups = Explode(",", $strGroups); 
    if (in_array($UserName, $arrUsers)) { 
      $isValid = true; 
    } 
    // Or, you may restrict access to only certain users based on their username. 
    if (in_array($UserGroup, $arrGroups)) { 
      $isValid = true; 
    } 
    if (($strUsers == "") && true) { 
      $isValid = true; 
    } 
  } 
  return $isValid; 
}

$MM_restrictGoTo = "admin/index.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0) 
  $MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo); 
  exit;
}
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_MyConnect, $MyConnect);
$query_Recordset1 = "SELECT * FROM purchase_detail";
$Recordset1 = mysql_query($query_Recordset1, $MyConnect) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

$maxRows_purchaseset1 = 5;
$pageNum_purchaseset1 = 0;
if (isset($_GET['pageNum_purchaseset1'])) {
  $pageNum_purchaseset1 = $_GET['pageNum_purchaseset1'];
}
$startRow_purchaseset1 = $pageNum_purchaseset1 * $maxRows_purchaseset1;


$query_purchaseset1 = "SELECT * FROM purchase_detail";
$query_limit_purchaseset1 = sprintf("%s LIMIT %d, %d", $query_purchaseset1, $startRow_purchaseset1, $maxRows_purchaseset1);
$purchaseset1 = mysql_query($query_limit_purchaseset1, $MyConnect) or die(mysql_error());
$row_purchaseset1 = mysql_fetch_assoc($purchaseset1);

if (isset($_GET['totalRows_purchaseset1'])) {
  $totalRows_purchaseset1 = $_GET['totalRows_purchaseset1'];
} else {
  $all_purchaseset1 = mysql_query($query_purchaseset1);
  $totalRows_purchaseset1 = mysql_num_rows($all_purchaseset1);
}
$totalPages_purchaseset1 = ceil($totalRows_purchaseset1/$maxRows_purchaseset1)-1;
?>
<!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>purchase_detail</title>

<script src="js/jquery.js" type="text/javascript"></script>
<link href="css/bootstrap.min.css" rel="stylesheet" type="text/css" />
</head>
<style type="text/css">
#MenuBar1 { 
	font-size: 230%;
	font-family: "Courier New", Courier, monospace;
}
body p {
	font-size: 18px;
	text-align: center;
	color: #000;
}
body h2 {
	text-align: center;
}
</style>

<body class='container'> 
<p><img src="shop.jpg" width="1117" height="149" />
</p>
<h3>ร้านเกสร
</h3>
<p>ระบบจัดการฐานข้อมูลสำหรับร้านค้าปลีก</p>

<div class="btn-group">
   <button class="btn"><a href="sales_detail.php">ขายสินค้า</a></button>
</div>

<div class="btn-group">
  <button class="btn">ข้อมูลพื้นฐาน</button>
  <button class="btn dropdown-toggle" data-toggle="dropdown">
    <span class="caret"></span>
  </button>  
  <ul class="dropdown-menu">
    <li><a href="Product.php">ข้อมูลสินค้า</a></li>
    <li><a href="Category.php">ข้อมูลประเภทสินค้า</a></li>
    <li><a href="Supplier.php">ข้อมูลผู้จัดจำหน่าย</a></li>
    <!-- dropdown menu links -->
  </ul> 
</div>

<div class="btn-group">
  <button class="btn"><a href="Unit.php">หน่วยสินค้า</a></button>
</div>

<div class="btn-group">
  <button class="btn"><a href="repayment">จัดการลูกหนี้</a></button>
</div>

<div class="btn-group">  
  <button class="btn">เพิ่มเติม</button>
  <button class="btn dropdown-toggle" data-toggle="dropdown">
    <span class="caret"></span>
  </button>  
  <ul class="dropdown-menu">
    <li><a href="#">ดูสินค้าใกล้หมด</a></li>
    <!-- dropdown menu links -->
  </ul>
</div>

  <div class="btn-group">
  <button class="btn"><a href="edit-profile.php">แก้ไขข้อมูลส่วนตัว</a></button>
</div>
  <div class="btn-group">
  <button class="btn"><a href="admin/index.php">ออกจากระบบ</a></button>
</div>
<p>&nbsp;</p>
<p>รายละเอียดการซื้อเข้า</p>
<p>
  <a href="addpurchase_detail.php"> 
  <input type="submit" name="btn" id="btn" value="เพิ่ม" />
</a></p>
<table table class="table table-bordered" width="105%" border="1">
  <tr class="success">
    <td width="196">รหัส</td>
    <td width="196">ชื่อสินค้า</td>
    <td width="213">วันที่ซื้อเข้า</td>
    <td width="238">ราคาต้นทุน</td>
    <td width="252">จำนวนสินค้าที่ซื้อเข้า</td>
    <td width="55">แก้ไข</td>
    <td width="55">ลบ</td>
   
  </tr>
  
  <?php
   $Total = 0;
   $SumTotal = 0;
  
   while($rs=mysql_fetch_array($QUERY))  {    
   $Total = $rs['product_qty'];
   $SumTotal = $SumTotal + $Total;
     ?>
    <tr>
      <td><?php echo $rs['id']; ?></td>
      <td><?php echo $rs['name']; ?></td>
      <td><?php echo $rs['pur_date']; ?></td>
      <td><?php echo $rs['pur_princ']; ?></td>
      <td><?php echo $rs['product_qty']; ?></td>
      <td><i class="icon-pencil"></i><a href="editpurchase_detail.php?pur_detail_id=<?php echo $rs['id']; ?>">แก้ไข</a></td>
      <td><i class="icon-trash"></i><a onclick="return confirm_delete()" href="deletePurchase_detail.php?pur_detail_id=<?php echo $rs['id']; ?>">ลบ</a></td>
      
    <?php } $rs= mysql_fetch_assoc($purchaseset1); ?>
</table>
<td align="right"><p>จำนวนสินค้าที่เก็บ <?php echo number_format($SumTotal);?> ชิ้น</p>
  <p>&nbsp;</p>

<script src="js/jquery.js"></script>
<script src="js/bootstrap.min.js"></script>
<script type="text/javascript">
function confirm_delete() {
  return confirm('ยืนยันการลบข้อมูล !');
}
</script>
<?php
mysql_free_result($purchaseset1);

mysql_free_result($Recordset1);
?>


code deletePurchase_detail.php
Code (PHP)
<?php require_once('Connections/MyConnect.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

if ((isset($_GET['pur_detail_id'])) && ($_GET['pur_detail_id'] != "")) {
  $deleteSQL = sprintf("DELETE FROM purchase_detail WHERE pur_detail_id=%s",
                       GetSQLValueString($_GET['pur_detail_id'], "int"));
$strSQL = "SELECT * FROM product WHERE product_id = '".$rs["product_id"]."'"; 
	$objQuery = mysql_query($strSQL)  or die(mysql_error());
	$objResult = mysql_fetch_array($objQuery);
   {
	$strSQL2 = "UPDATE product SET product_qty = product_qty - ".$rs['product_qty']." WHERE product_id = '".$_REQUEST['product_id']."'";
	$objQuery = mysql_query($strSQL2)  or die(mysql_error());
			}							   
  mysql_select_db($database_MyConnect, $MyConnect);
  $Result1 = mysql_query($deleteSQL, $MyConnect) or die(mysql_error());
  
  $deleteGoTo = "Purchase_detail.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
    $deleteGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $deleteGoTo));
}
?>
<!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>deletePurchase_detail</title>
</head>

<body>
</body>
</html>




Tag : PHP, MySQL, HTML/CSS, JavaScript, jQuery, CakePHP









ประวัติการแก้ไข
2016-05-22 17:18:27
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2016-05-21 20:57:47 By : suwidha View : 752 Reply : 2
 

 

No. 1

Guest


ยาวไปไม่อ่าน

เอาแค่ delete + update ก็ใช้ transection สิ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-05-23 09:10:52 By : ห้ามตอบเกินวันละ 2 กระทู้
 


 

No. 2



โพสกระทู้ ( 484 )
บทความ ( 3 )



สถานะออฟไลน์


ใช้ Transection สิ

Code (PHP)
mysql_query("BEGIN");

$num = x; //qty สำหรับลบและ update
$query1: delete ข้อมูล
$query2: update ข้อมูล
$query3: อื่นๆ ถ้ามี

if(($query1) && ($query2)) // if(($query1) && ($query2) && ($query3))
{
	mysql_query("COMMIT");
}
else
{
	mysql_query("ROLLBACK");
}


CI
Code (PHP)
$this->db->trans_begin();

$this->db->query('DELTE QUERY...');
$this->db->query('UPDATE QUERY...');
$this->db->query('อื่นๆ...');

if ($this->db->trans_status() === FALSE)
{
    $this->db->trans_rollback();
}
else
{
    $this->db->trans_commit();
}


เจริญพร...
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-05-23 10:19:45 By : fossil31
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ขอคำแนะนำเรื่องการลบข้อมูล พร้อม Update ข้อมูลไปพร้อมๆกันครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 05
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่