|
|
|
อยากสอบถามเรื่องการ Insert แบบ Multi row โดยทำการวนลูป check ชื่อ Field ถ้าตรงกับ Field ไหนให้ใส่ช่องนั้น |
|
|
|
|
|
|
|
อยากสอบถามเรื่องการ Insert แบบ Multi row โดยทำการวนลูป check ชื่อ Field ถ้าตรงกับ Field ไหนให้ใส่ช่องนั้นครับ
คือตามรูป DEFECT CLASSIFY ประเภทของ Defect ใน database มี 48 defect แต่ผมจะให้ User เลือก defect ที่ต้องการลงข้อมูลแค่ 8 Defect หรือน้อยกว่า ดังนั้นเวลา User Submit อยากให้ Defect ที่ User เลือกถ้าตรงกับ Field ใดใน Database ก็ให้ลงช่องนั้นครับ พี่ ๆ thaicreate ช่วยแนะนำด้วยนะครับ
Code การ Insert ที่ลองเขียนแล้วครับ
Code (PHP)
<td align="center" valign="middle" bgcolor="#E0E0E0"><input name="txtDef2<?=$i;?>" type="text" id="txtDef2" size="3" /></td>
<td align="center" valign="middle" bgcolor="#E0E0E0"><input name="txtDef3<?=$i;?>" type="text" id="txtDef3" size="3" /></td>
<td align="center" valign="middle" bgcolor="#E0E0E0"><input name="txtDef4<?=$i;?>" type="text" id="txtDef4" size="3" /></td>
<td align="center" valign="middle" bgcolor="#E0E0E0"><input name="txtDef5<?=$i;?>" type="text" id="txtDef5" size="3" /></td>
<td align="center" valign="middle" bgcolor="#E0E0E0"><input name="txtDef6<?=$i;?>" type="text" id="txtDef6" size="3" /></td>
<td align="center" valign="middle" bgcolor="#E0E0E0"><input name="txtDef7<?=$i;?>" type="text" id="txtDef7" size="3" /></td>
<td align="center" valign="middle" bgcolor="#E0E0E0"><input name="txtDef8<?=$i;?>" type="text" id="txtDef8" size="3" /></td>
<?PHP
//onclick="Asubmit(this.form);"
include("DB-config.php");
if(isset($_POST['btSubmit']))
{
for($i=1;$i<9;$i++){
if($_POST['lstRea'.$i]=="SIN"){
$_POST['txtDef'.$i];
}else if($_POST['lstRea'.$i]=="ESK"){
$_POST['txtDef'.$i];
}else if($_POST['lstRea'.$i]=="COS"){
$DefNum3 = $_POST['txtDef'.$i];
}else if($_POST['lstRea'.$i]=="BRO"){
$DefNum4 = $_POST['txtDef'.$i];
}else if($_POST['lstRea'.$i]=="MBR"){
$DefNum5 = $_POST['txtDef'.$i];
}else if($_POST['lstRea'.$i]=="SLA"){
$DefNum6 = $_POST['txtDef'.$i];
}else if($_POST['lstRea'.$i]=="HB"){
$DefNum7 = $_POST['txtDef'.$i];
}else if($_POST['lstRea'.$i]=="GAS"){
$DefNum8 = $_POST['txtDef'.$i];
}else if($_POST['lstRea'.$i]=="DIM"){
$DefNum9 = $_POST['txtDef'.$i];
}else if($_POST['lstRea'.$i]=="POE"){
$DefNum10 = $_POST['txtDef'.$i];
}else if($_POST['lstRea'.$i]=="MOF"){
$DefNum11 = $_POST['txtDef'.$i];
}else if($_POST['lstRea'.$i]=="CSH"){
$DefNum12 = $_POST['txtDef'.$i];
}else if($_POST['lstRea'.$i]=="UNC"){
$DefNum13 = $_POST['txtDef'.$i];
}else if($_POST['lstRea'.$i]=="ISK"){
$DefNum14 = $_POST['txtDef'.$i];
}else if($_POST['lstRea'.$i]=="MEC"){
$DefNum15 = $_POST['txtDef'.$i];
}else if($_POST['lstRea'.$i]=="CHE"){
$DefNum16 = $_POST['txtDef'.$i];
}else if($_POST['lstRea'.$i]=="SBU"){
$DefNum17 = $_POST['txtDef'.$i];
}else if($_POST['lstRea'.$i]=="FIN"){
$DefNum18 = $_POST['txtDef'.$i];
}else if($_POST['lstRea'.$i]=="SCA"){
$DefNum19 = $_POST['txtDef'.$i];
}else if($_POST['lstRea'.$i]=="ERO"){
$DefNum20 = $_POST['txtDef'.$i];
}else if($_POST['lstRea'.$i]=="MNG"){
$DefNum21 = $_POST['txtDef'.$i];
}else if($_POST['lstRea'.$i]=="MTL"){
$DefNum22 = $_POST['txtDef'.$i];
}else if($_POST['lstRea'.$i]=="BLR"){
$DefNum23 = $_POST['txtDef'.$i];
}else if($_POST['lstRea'.$i]=="CBR"){
$DefNum24 = $_POST['txtDef'.$i];
}else if($_POST['lstRea'.$i]=="CHI"){
$DefNum25 = $_POST['txtDef'.$i];
}else if($_POST['lstRea'.$i]=="COF"){
$DefNum26 = $_POST['txtDef'.$i];
}else if($_POST['lstRea'.$i]=="COT"){
$DefNum27 = $_POST['txtDef'.$i];
}else if($_POST['lstRea'.$i]=="CRA"){
$DefNum28 = $_POST['txtDef'.$i];
}else if($_POST['lstRea'.$i]=="CUT"){
$DefNum29 = $_POST['txtDef'.$i];
}else if($_POST['lstRea'.$i]=="EXP"){
$DefNum30 = $_POST['txtDef'.$i];
}else if($_POST['lstRea'.$i]=="FIS"){
$DefNum31 = $_POST['txtDef'.$i];
}else if($_POST['lstRea'.$i]=="HOS"){
$DefNum32 = $_POST['txtDef'.$i];
}else if($_POST['lstRea'.$i]=="KNB"){
$DefNum33 = $_POST['txtDef'.$i];
}else if($_POST['lstRea'.$i]=="LOT"){
$DefNum34 = $_POST['txtDef'.$i];
}else if($_POST['lstRea'.$i]=="MC"){
$DefNum35 = $_POST['txtDef'.$i];
}else if($_POST['lstRea'.$i]=="MIC"){
$DefNum36 = $_POST['txtDef'.$i];
}else if($_POST['lstRea'.$i]=="MIR"){
$DefNum37 = $_POST['txtDef'.$i];
}else if($_POST['lstRea'.$i]=="MOS"){
$DefNum38 = $_POST['txtDef'.$i];
}else if($_POST['lstRea'.$i]=="NKO"){
$DefNum39 = $_POST['txtDef'.$i];
}else if($_POST['lstRea'.$i]=="PEN"){
$DefNum40 = $_POST['txtDef'.$i];
}else if($_POST['lstRea'.$i]=="PH"){
$DefNum41 = $_POST['txtDef'.$i];
}else if($_POST['lstRea'.$i]=="PUL"){
$DefNum42 = $_POST['txtDef'.$i];
}else if($_POST['lstRea'.$i]=="RUS"){
$DefNum43 = $_POST['txtDef'.$i];
}else if($_POST['lstRea'.$i]=="SHB"){
$DefNum44 = $_POST['txtDef'.$i];
}else if($_POST['lstRea'.$i]=="SHO"){
$DefNum45 = $_POST['txtDef'.$i];
}else if($_POST['lstRea'.$i]=="SWO"){
$DefNum46 = $_POST['txtDef'.$i];
}else if($_POST['lstRea'.$i]=="THN"){
$DefNum47 = $_POST['txtDef'.$i];
}else if($_POST['lstRea'.$i]=="WMT"){
$DefNum48 = $_POST['txtDef'.$i];
}
};
$new_id =mysql_result(mysql_query("Select Max(substr(Defect_Id,-4))+1 as MaxID from tbdefect"),0,"MaxID");
if($new_id==''){
$frontD=date("ym-");
for($n=1;$n<$_POST['hdnLine'];$n++){
$j=$n+1;
$std_id[]="$frontD"."000$j";
}
}else{
$frontD=date("ym-");
for($n=1;$n<=$_POST['hdnLine'];$n++){
$std_id[]="$frontD".sprintf("%04d",$new_id+$n);
}
}
for($i=1;$i<$_POST["hdnLine"];$i++)
{
if($_POST["txtPartName"] != "")
{
$strSQL = "INSERT IGNORE INTO tbapprdefect ";
$strSQL .="(`Defect_Id`,`Defect_Date`, `PartName`, `Name`, `Refer`, `Cust`, `ChkDate`,`LotNo`, `Prod`,`SIN`, `ESK`, `COS`, `MBR`, `SLA`, `HB`, `GAS`, `DIM`, `POE`, `MOF`, `CSH`, `UNC`, `ISK`, `MEC`, `CHE`, `SBU`, `FIN`, `SCA`, `ERO`, `MNG`, `MTL`, `BLR`, `CBR`, `CHI`, `COF`, `COT`, `CRA`, `CUT`, `EXP`, `FIS`, `HOS`, `KNB`, `LOT`, `MC`, `MIC`, `MIR`, `MOS`, `NKO`, `PEN`, `PH`, `PUL`, `RUS`, `SHB`, `SHO`, `SWO`, `THN`, `WMT`) ";
$strSQL .="VALUES ";
$strSQL .="('".$std_id[$i]."' ";
$strSQL .=",'".$_POST["txtDate"]."','".$_POST["txtPartName"]."' ";
$strSQL .=",'".$_POST["txtName"]."', '".$_POST["txtRefer"]."' ";
$strSQL .=",'".$_POST["lstCust"]."','".$_POST["txtChkDate"]."' ";
$strSQL .=",'".$_POST["txtLotNo".$i]."','".$_POST["txtProd".$i]."' ";
$strSQL .=",'".$DefNum1."','".$DefNum2."' ";
$strSQL .=",'".$DefNum3."','".$DefNum4."' ";
$strSQL .=",'".$DefNum5."','".$DefNum6."' ";
$strSQL .=",'".$DefNum7."','".$DefNum8."' ";
$strSQL .=",'".$DefNum9."','".$DefNum10."' ";
$strSQL .=",'".$DefNum11."','".$DefNum12."' ";
$strSQL .=",'".$DefNum13."','".$DefNum14."' ";
$strSQL .=",'".$DefNum15."','".$DefNum16."' ";
$strSQL .=",'".$DefNum17."','".$DefNum18."' ";
$strSQL .=",'".$DefNum19."','".$DefNum20."' ";
$strSQL .=",'".$DefNum21."','".$DefNum22."' ";
$strSQL .=",'".$DefNum23."','".$DefNum24."' ";
$strSQL .=",'".$DefNum25."','".$DefNum26."' ";
$strSQL .=",'".$DefNum27."','".$DefNum28."' ";
$strSQL .=",'".$DefNum29."','".$DefNum30."' ";
$strSQL .=",'".$DefNum31."','".$DefNum32."' ";
$strSQL .=",'".$DefNum33."','".$DefNum34."' ";
$strSQL .=",'".$DefNum35."','".$DefNum36."' ";
$strSQL .=",'".$DefNum37."','".$DefNum38."' ";
$strSQL .=",'".$DefNum39."','".$DefNum40."' ";
$strSQL .=",'".$DefNum41."','".$DefNum42."' ";
$strSQL .=",'".$DefNum43."','".$DefNum44."' ";
$strSQL .=",'".$DefNum45."','".$DefNum46."' ";
$strSQL .=",'".$DefNum47."','".$DefNum48."' ) ";
$objQuery = mysql_query($strSQL);
if($objQuery){
echo "<script>alert('Insert Daily Defect data successful.')</script>";
}else{
echo "Error Save [".$strSQL."]";
}
}
}
};
?>
Tag : PHP, MySQL, Windows
|
|
|
|
|
|
Date :
2014-02-12 21:01:41 |
By :
TotEcom |
View :
1294 |
Reply :
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date :
2014-02-12 21:04:26 |
By :
meannerss |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอดู table structure ด้วยครับ
|
|
|
|
|
Date :
2014-02-12 21:23:39 |
By :
itpcc |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
table ครับ
http://www.4shared-remove-by-admin.com/get/eUtpGoYNba/tbdefect.html
|
|
|
|
|
Date :
2014-02-12 22:00:40 |
By :
TotEcom |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
พี่ ๆ ช่วยแนะนำหน่อยครับ ผมงมมานานแล้วยังไม่ได้เลย
|
ประวัติการแก้ไข 2014-02-13 10:04:15
|
|
|
|
Date :
2014-02-13 09:11:03 |
By :
TotEcom |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ยังไม่ได้เลย
|
|
|
|
|
Date :
2014-02-14 13:43:10 |
By :
TotEcom |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|