|
 |
|
รบกวนช่วยแก้หน่อยครับ จะบันทึก array พอ echo ดูได้ 3 รอบแต่บันทุกลง database จริงได้แค่รอบเดียวเลย งง ครับ |
|
 |
|
|
 |
 |
|
รบกวนช่วยแก้หน่อยครับ จะบันทึก array พอ echo ดูได้ 3 รอบแต่บันทุกลง database จริงได้แค่รอบเดียวเลย งง ครับ

Code (PHP)
// บันทึก Order
$sqlorder = "INSERT INTO tb_order VALUES ('$neworderid','$neworderid','$datetimenow','$ordername','$orderdepartment','$orderstatus','','$ordernote','$useridsession')";
//$queryorder = mysqli_query($conn, $sqlorder);
//echo count($_POST['txt_id']);
$itemid = $_POST['txt_id'];
$itemamount = $_POST['txt_qty'];
//if ($queryorder) {
for ($i = 0; $i < count($itemid); $i++) {
$datenow = date("Ym");
$sqlnewid = "SELECT Max(substr(Order_id,-3))+1 as MaxID FROM tb_order WHERE LEFT(Order_id, 6)='$datenow'";
$querynewid = mysqli_query($conn, $sqlnewid);
$resultnewid = mysqli_fetch_assoc($querynewid);
//echo $resultnewid['MaxID'];
if ($resultnewid['MaxID'] == '') { // ถ้าได้เป็นค่าว่าง หรือ null ก็แสดงว่ายังไม่มีข้อมูลในฐานข้อมูล
$newodetailid = $datenow . '-' . '0001';
} else {
$newodetailid = $datenow . '-' . sprintf('%04d', $resultnewid['MaxID']);
}
//บันทึก Order_detail
echo $sqldetail = "INSERT INTO tb_orderdetail VALUES ('$newodetailid','$neworderid','$itemid[$i]','$itemamount[$i]')";
//$querydetail = mysqli_query($conn, $sqldetail);
if ($querydetail) {
//echo("<script> alert('บันทึกข้อมูลเรียบร้อยแล้ว'); window.location = 'FrmEquip.php?db=Equip';</script>");
} else {
//echo("<script> alert('ไม่สามารถบันทึกข้อมูลได้'); window.location = 'javascript:window.history.back()';</script>");
}
}
//}
Tag : PHP

|
|
 |
 |
 |
 |
Date :
2018-08-28 18:49:49 |
By :
PACKLpk |
View :
554 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอาออกไปอยู่ข้างนอก for ครับ
Code (PHP)
if ($querydetail) {
echo("<script> alert('บันทึกข้อมูลเรียบร้อยแล้ว'); window.location = 'FrmEquip.php?db=Equip';</script>");
} else {
echo("<script> alert('ไม่สามารถบันทึกข้อมูลได้'); window.location = 'javascript:window.history.back()';</script>");
}
|
 |
 |
 |
 |
Date :
2018-08-29 18:13:29 |
By :
Jatmentz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|