|
|
|
ขอคำแนะนำหน่อยครับ php เขียน select ฐานข้อมูล mysql แล้วทำการ Update โดย ลบค่าใน felds นั้น โดยใช้ Where |
|
|
|
|
|
|
|
มีอยู่ว่า " SELECT Table bill_out WHERE BillNo เพื่อ search เลข BillNo
จากนั้น เอาค่า QTY ของ bill_out มา ลบ Delete ค่า ของ StockMain จาก stock_main
แต่ลบ ยังไงก็ไม่ได้ ถ้าท่านไหนพอจะรู้แนะนำผมที่ ครับ งงมากเลย
-------------
code.php
Code (PHP)
<?php
session_start();
ob_start();
$ProductID=$_POST['ProductID'];
echo $ProductID;
$BillNo=$_POST['BillNo'];
echo $BillNo;
$QTY=$_POST['QTY'];
echo $QTY;
include("include/db_connect.php");
include("include/function.php");
if((isset($_SESSION['login_true_administrator'])) or (isset($_SESSION['login_true_AdminID'])))
{
?>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="css/textcss.css" type="text/css" rel="stylesheet" >
<link href="css/styleinput.css" type="text/css" rel="stylesheet" >
<link href="css/stylelink.css" type="text/css" rel="stylesheet">
<form action="#" method="post" enctype="multipart/form-data" name="frm">
<?php
$selectBill="SELECT * FROM stock_d.bill_out WHERE BillNo ='$BillNo'";
$sqlBill=mysql_query($selectBill)or die ("Show Error ::".mysql_error());
if(isset($sqlBill)){
$selectmain="SELECT * FROM stock_d.stock_main WHERE ProductID='$ProductID'";
$Qrymain=mysql_query($selectmain) or die("Error select main that:".mysql_error());
while($Rowsed=mysql_fetch_array($Qrymain)){
$proID=$Rowsed['ProductID'];
$main=$Rowsed['StockMain'];
}
if(isset($Qrymain)){
$main=$StockMain-$QTY;
if(isset($main))
{
$updating=mysql_query("UPDATE stock_d.stock_main SET
StockMain ='$main'
WHERE stock_main.ProductID ='$ProductID'
") or die("update faild that:".mysql_error());
echo "<meta http-equiv='refresh' content='0;url=out_bill.php'>";
echo "<script>alert('ບັນທຶກຂໍ້ມູນຮຽບຮ້ອຍແລ້ວ !!!');</script>";
}
}
else{ echo "No Main!!"; }
}
?>
<table width="81%" border="1" align="center"cellpadding="1" cellspacing="0" bordercolor="#CCCCCC" style='BORDER-COLLAPSE: collapse'>
<tr>
<td colspan="5">ຄົ້ນຫາ <img src="img/zoom_in.png" width="16" height="16"><input type="search" id="BillNo" name="BillNo"> <input name="search" type="submit" id="search" value="search"></td>
</tr>
<tr>
<td>BillNo:</td>
<td>ProductID/ລະຫັດເຄື່ອງ</td>
<td>Name/ຊື່</td>
<td>NameLao/ຊື່ລາວ</td>
<td>QTY/ຈຳນວນ</td>
</tr>
<?php
$i =0;
while($row=mysql_fetch_array($sqlBill))
{
$i = $i + 1;
?>
<tr>
<td><?php echo $row['BillNo']; ?></td>
<td><input type="text" name="ProductID<?php echo $i;?>" value="<?php echo $row['ProductID']; ?>" /></td>
<td><input type="text" name="Name<?php echo $i;?>" value="<?php echo $row['Name']; ?>" /></td>
<td><input type="text" name="NameLao<?php echo $i;?>" value=" <?php echo $row['NameLao']; ?>" /></td>
<td><input type="text" name="QTY<?php echo $i;?>" id="QTY"value="<?php echo $row['QTY']; ?>" /></td>
</tr>
<?php } ?>
<tr>
<td colspan="5" align="center"><input type="submit" name="delete" id="delete" value="Cut Stock"> <input type="reset" name="reset" id="reset" value="reset">
</td>
</tr>
</table>
<?php
?>
<?php }?>
</form>
<?php
ob_end_flush();
mysql_close($d1,$db1,$c1);
mysql_close($d2,$db2,$c1);
exit();
?>
---------
db_connect.php
Code (PHP)
<?php
$hostname1="localhost";
$username1="root";
$password1="44@44";
$db1="stock_d";
$db2="staffdata";
$c1=mysql_connect($hostname1,$username1,$password1,"TRUE");
$d1=mysql_select_db($db1,$c1)or die((mysql_error));
$d2=mysql_select_db($db2,$c1)or die((mysql_error));
mysql_query("SET NAMES 'utf8'",$c1);
set_time_limit(0);
if(!$c1){
echo "( ERROR : Connect Server $hostname1 !!!)";
exit();
}else if(!$d1){
echo "( ERROR : Connect MySql Server $db1 !!!)";
exit();
}else if(!$d2){
echo "( ERROR : Connect MySql Server $db2 !!!)";
exit();
}
//====================================================
foreach($_GET as $varname=>$varvalue){
if(empty($varvalue)){
$empty[$varname]=$varvalue;
}else{
$get[$varname]=$varvalue;
}
$$varname=$varvalue;
}
foreach($_POST as $varname=>$varvalue) {
if(empty($varvalue)){
$empty[$varname]=$varvalue;
}else{
$post[$varname]=$varvalue;
}
$$varname=$varvalue;
}
//====================================================
?>
Code (SQL)
-------------
CREATE TABLE IF NOT EXISTS `bill_out` (
`CodeOut` int(10) NOT NULL AUTO_INCREMENT,
`BillNo` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
`ProductID` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
`Name` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
`NameLao` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
`QTY` int(255) NOT NULL,
`KindID` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
`Remark` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`BillNo`,`ProductID`),
UNIQUE KEY `CodeOut` (`CodeOut`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=3 ;
--
-- dump ตาราง `bill_out`
--
INSERT INTO `bill_out` (`CodeOut`, `BillNo`, `ProductID`, `Name`, `NameLao`, `QTY`, `KindID`, `Remark`) VALUES
(1, 'IT-00001', 'BE-00001', 'COFFEE', 'ກາເຟ', 1, 'ຖົງ', ''),
(2, 'IT-00001', 'BE-00002', 'SUGER', 'ນ້ຳຕານ', 1, 'ຖົງ', '');
------------------------------
-- phpMyAdmin SQL Dump
-- version 3.2.0.1
-- http://www.phpmyadmin.net
--
-- โฮสต์: localhost
-- เวลาในการสร้าง:
-- รุ่นของเซิร์ฟเวอร์: 5.1.37
-- รุ่นของ PHP: 5.3.0
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
--
-- ฐานข้อมูล: `stock_d`
--
-- --------------------------------------------------------
--
-- โครงสร้างตาราง `stock_main`
--
CREATE TABLE IF NOT EXISTS `stock_main` (
`StockMainID` int(10) NOT NULL AUTO_INCREMENT,
`ProductID` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
`Name` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`NameLao` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`StockMain` int(255) DEFAULT NULL,
`DateStockMain` date DEFAULT NULL,
PRIMARY KEY (`ProductID`),
UNIQUE KEY `StockMainID` (`StockMainID`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=576 ;
--
-- dump ตาราง `stock_main`
--
INSERT INTO `stock_main` (`StockMainID`, `ProductID`, `Name`, `NameLao`, `StockMain`, `DateStockMain`) VALUES
(160, 'OS-00061', 'INK FOR STAMP/RED', 'ນ້ຳມືກໃສ່ແຜ່ນຈຳ', 100, '2017-05-12'),
(159, 'OS-00011', 'BLACK CLIP MIDDLE/NO:109', 'ກິບດຳເບ109', 100, '2017-05-12'),
-----------------------
Tag : PHP, MySQL, PDF, Google Chrome, Apache, XAMPP
|
|
|
|
|
|
Date :
2017-05-24 17:20:28 |
By :
Bouasavanh HararRock |
View :
991 |
Reply :
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ไม่มีคำสั่ง DELETE เลยนะครับ
|
|
|
|
|
Date :
2017-05-25 05:04:34 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
จากที่ดู code เหมือนแค่เอามาแสดงเฉยๆ ยังไม่มีฟังก์ชั่นการ delete อะไร
ลองเขียนฟังก์ชั่นหลังจากกดปุ่มดูครับ
รู้สึกจะมีปุ่ม 2 ปุ่มในตาราง
|
|
|
|
|
Date :
2017-05-25 15:20:41 |
By :
zadstoms |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
กำลังหาวิธีใหม่ ทำ แต่มันไม่บันทืกครับ งง กับเรื่อง [$i] Array ที่จะทำการ Update
Code (PHP)
<?php
include("include/db_connect.php");
include("include/function.php");
$ProductID=$_POST['ProductID'];
$selectBill=" SELECT stock_d.bill_out.BillNo,
stock_d.bill_out.ProductID,
stock_d.bill_out.Name,
stock_d.bill_out.NameLao,
stock_d.bill_out.QTY,
stock_d.stock_main.StockMain,
stock_d.stock_main.StockMain - stock_d.bill_out.QTY AS Resulted
FROM stock_d.bill_out
LEFT JOIN stock_d.stock_main ON stock_d.stock_main.ProductID = bill_out.ProductID WHERE BillNo ='$BillNo'";
$sqlBill=mysql_query($selectBill)or die ("Show Error ::".mysql_error());
if(isset($sqlBill))
{
$selectmain="SELECT stock_d.stock_main.ProductID,
stock_d.stock_main.Name,
stock_d.stock_main.NameLao,
stock_d.stock_main.StockMain,
stock_d.bill_out.QTY,
stock_d.stock_main.StockMain-stock_d.bill_out.QTY AS Resulted
FROM stock_d.stock_main
LEFT JOIN stock_d.bill_out ON stock_d.bill_out.ProductID = stock_main.ProductID
WHERE stock_main.ProductID = '$ProductID'";
$Qrymain=mysql_query($selectmain) or die ("Error select main that:: ".mysql_error());
while($Rowsed=mysql_fetch_array($Qrymain))
{
$proID=$Rowsed['ProductID'];
$QTYO=$Rowsed['QTY'];
$StockMain=$Rowsed['StockMain'];
$Resulted=$StockMain-$QTYO;
echo $Resulted;
echo $QTYO;
echo $StockMain;
}
if(isset($Qrymain))
{
$proID;
$QTYO;
$StockMain;
$Resulted;
echo $Resulted;
if(isset($Resulted))
{
echo $Resulted;
if($_POST["submit"]=="delete")
echo $Resulted;
{
$updating=mysql_query("UPDATE stock_d.stock_main SET stock_main.StockMain ='$Resulted' WHERE stock_main.ProductID = '$ProductID'")
or die("update faild that:".mysql_error());
echo "<meta http-equiv='refresh' content='0;url=0001.php'>";
echo "<script>alert('ບັນທຶກຂໍ້ມູນຮຽບຮ້ອຍແລ້ວ !!!');</script>";
}
}echo "No Main!!";{
}
}
}
?>
<form action="#" method="post" enctype="multipart/form-data" name="frm">
<table width="81%" border="1" align="center"cellpadding="1" cellspacing="0" bordercolor="#CCCCCC" style='BORDER-COLLAPSE: collapse'>
<tr>
<td colspan="7">ຄົ້ນຫາ <img src="img/zoom_in.png" width="16" height="16"><input type="search" id="BillNo" name="BillNo"> <input name="search" type="submit" id="search" value="search"></td>
</tr>
<tr>
<td>BillNo:</td>
<td>ProductID/ລະຫັດເຄື່ອງ</td>
<td>Name/ຊື່</td>
<td>NameLao/ຊື່ລາວ</td>
<td>QTY/ຈຳນວນ</td>
<td>StockMain</td>
<td>Result</td>
</tr>
<?php
$i=1;
while($row=mysql_fetch_array($sqlBill))
{
$i=$i++;
?>
<tr>
<td><?php echo $row['BillNo']; ?></td>
<td><input type="text" name="ProductID<?php echo $i?>" value="<?php echo $row['ProductID']; ?>" /></td>
<td><input type="text" name="Name<?php echo $i?>" value="<?php echo $row['Name']; ?>" /></td>
<td><input type="text" name="NameLao<?php echo $i?>" value=" <?php echo $row['NameLao']; ?>" /></td>
<td><input type="text" name="QTY<?php echo $i?>"value="<?php echo $row['QTY']; ?>" /></td>
<td><input type="text" name="StockMain<?php echo $i?>" value="<?php echo $row['StockMain']; ?>" /></td>
<td><input type="text" name="Result<?php echo $i?>" value="<?php echo $row ['Resulted'];?>"/></td>
</tr>
<?php } ?>
<tr>
<td colspan="7" align="center"><input type="submit" name="delete" id="delete" value="delete"> <input type="reset" name="reset" id="reset" value="reset">
</td>
</tr>
</table>
|
|
|
|
|
Date :
2017-05-26 08:19:26 |
By :
Bouasavanh HararRock |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
กะทู้นี้ Clear All น่ะครับ ทำได้เบิดแล้ว
ขอบคุณมากๆครับ Thaicreate
|
|
|
|
|
Date :
2017-05-30 13:20:57 |
By :
Bouasavanh HararRock |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|