|
 |
|
insert ข้อมูลแล้ว วนลูปครบตามจำนวน แต่ข้อมูลที่เข้าไปเป็นของบรรทัดสุดท้าย ทั้งหมด |
|
 |
|
|
 |
 |
|
รบกวนช่วยดูโค้ดทีครับ เพราะเวลา database รับค่าไปจะได้แต่ข้อมูลบรรทัดสุดท้าย แต่จำนวนบรรทัดที่วนลูปนั้นตามที่ต้องการ และตรง process_id และ process_quantity จะได้รับค่าเป็น 0 ครับ
Form input ข้อมูล รับค่ามาจาก database แล้วแสดงบรรทัดออกมาตามจำนวน process Code (PHP)
<?php require_once('Connections/op3.php'); ?>
<?php
mysql_select_db($database_op3, $op3);
$query_lstteam = "SELECT * FROM team";
$lstteam = mysql_query($query_lstteam, $op3) or die(mysql_error());
$row_lstteam = mysql_fetch_assoc($lstteam);
$totalRows_lstteam = mysql_num_rows($lstteam);
mysql_select_db($database_op3, $op3);
$query_recordquantity = "SELECT * FROM process_quantity";
$recordquantity = mysql_query($query_recordquantity, $op3) or die(mysql_error());
$row_recordquantity = mysql_fetch_assoc($recordquantity);
$totalRows_recordquantity = mysql_num_rows($recordquantity);
mysql_select_db($database_op3, $op3);
$query_repertrecord = "SELECT process.process_name ,product_to_process.process_id , product_to_process.process_number FROM process INNER JOIN product_to_process ON (process.process_id = product_to_process.process_id) WHERE product_to_process.product_id = ".$product_list." ORDER BY product_to_process.process_number ASC ";
$repertrecord = mysql_query($query_repertrecord, $op3) or die(mysql_error());
$row_repertrecord = mysql_fetch_assoc($repertrecord);
$totalRows_repertrecord = mysql_num_rows($repertrecord);
?>
<form action="saveprocessquantity.php" method="POST" name="addproductquantity" id="addproductquantity">
<table width="200" border="0" align="center" cellpadding="0" cellspacing="3">
<tr>
<td align="center"><table width="325" border="1" align="center">
<tr>
<td width="154">Product Name</td>
<td width="155"><input name="txtproductname" type="text" value="<? echo $_REQUEST["product_list"];?>" readonly="readonly" /></td>
</tr>
<tr>
<td>Date ( dd-mm-yyyy )</td>
<td><label for="date"></label>
<input name="date" type="text" id="date" value="<? echo date("20y-m-d") ;?>" readonly="readonly" /></td>
</tr>
<tr>
<td>Team</td>
<td><label for="lstteam"></label>
<select name="lstteam" id="lstteam">
<option value="">Select Team</option>
<?php
do {
?>
<option value="<?php echo $row_lstteam['team_id']?>"><?php echo $row_lstteam['team_name']?></option>
<?php
} while ($row_lstteam = mysql_fetch_assoc($lstteam));
$rows = mysql_num_rows($lstteam);
if($rows > 0) {
mysql_data_seek($lstteam, 0);
$row_lstteam = mysql_fetch_assoc($lstteam);
}
?>
</select> <label for="teamlist"></label></td>
</tr>
</table></td>
</tr>
<tr>
<td><table width="539" border="1" align="center">
<tr>
<td width="195" align="center">Process Number</td>
<td width="182" align="center">Process name</td>
<td width="140" align="center">Quantity</td>
</tr>
<?php do { ?>
<tr>
<td width="195" align="center"><?php echo $row_repertrecord['process_number']; ?></td>
<td width="182" align="center"><input type="hidden" name="process_idhid" id="process_idhid" value="<?php echo $row_repertrecord['process_id']; ?>" />
<label for="processname"> <?php echo $row_repertrecord['process_name']; ?></label></td>
<td width="140" align="center"><label for="quantity"></label>
<input type="text" name="quantity" id="quantity" /></td>
</tr>
<?php } while ($row_repertrecord = mysql_fetch_assoc($repertrecord)); ?>
<tr>
<td align="center"> Total Process =
<label for="totalprocess"></label>
<input name="totalprocess" type="text" id="totalprocess" value="<?php echo $totalRows_repertrecord ?>" size="4" readonly="readonly" /></td>
<td align="center"> </td>
<td align="center"><label for="Sum"></label>
<input name="Sum" type="text" id="sum" value="" readonly="readonly" /></td>
</tr>
</table></td>
</tr>
<tr>
<td align="center"><input type="submit" name="Submit" id="Submit" value="Submit" /></td>
</tr>
</table>
</form>
<?php
mysql_free_result($lstteam);
mysql_free_result($recordquantity);
mysql_free_result($repertrecord);
?>
รับค่าจากข้างบน แล้วนำไปใส่ใน database Code (PHP)
<?php require_once('Connections/op3.php'); ?>
<?
mysql_select_db($database_op3);
for($i=1;$i<=$_POST["totalprocess"];$i++)
{
$strSQL = "INSERT INTO process_quantity ";
$strSQL .="(team_id, product_id , process_id , process_quantity , date) ";
$strSQL .="VALUES ";
$strSQL .="('".$_POST["lstteam"]."','".$_POST["txtproductname"]."','".$_POST["process_idhid$i"]."','".$_POST["quantity$i]"]."', " ;
$strSQL .="'".$_POST["date"]."')";
$objQuery = mysql_query($strSQL);
}
mysql_close($op3);
?>
Tag : PHP, MySQL, Windows

|
|
 |
 |
 |
 |
Date :
2012-07-31 15:05:53 |
By :
numaca |
View :
2617 |
Reply :
6 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
echo $strSQL."<br><br>";
$objQuery = mysql_query($strSQL);
เอา Query มาดูหน่อยครับ ว่ามันทำทุก Loop หรือเปล่า
|
 |
 |
 |
 |
Date :
2012-08-01 06:58:21 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แสดงผลออกมาลูปเดียวครับ แต่ในฐานข้อมูล มันใส่ไป 20 ครั้ง ตามที่รับค่ามา คือวนลูปตามจำนวนที่ถูกต้อง(ให้รับค่ามาโดยสั่งให้เช็คจำนวน process ตามชื่อ product ว่ามี ขั้นตอนการ process งานเท่าใหร่ ) แต่ใส่ค่าไม่ได้ตามที่เราต้องการ อีกอย่างคือ process_id , process_quantity มามีค่าเป็น 0 คือใส่ไปแล้ว แต่ไม่รับค่าเข้า database Code (PHP)
INSERT INTO process_quantity (team_id, product_id , process_id , process_quantity , date) VALUES ('1','1','','', '2012-08-01')
หรืออาการนี้คือ รับค่ามาแค่บรรทัดเดียว แต่วนใส่ในฐานข้อมูล ตามลูป
รบกวนช่วยดูด้วยครับ พอดีมือใหม่ แถมเลยกำหนดส่งมาสองวันแล้วด้วย
|
 |
 |
 |
 |
Date :
2012-08-01 08:04:50 |
By :
numaca |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอนนี้ได้แล้วครับ เพิ่ม [] หลัง ชื่อ text field เข้าไป เช่น
<input name="quantity[]" type="text" id="quantity" value="0" />
แล้วไปเพิ่มอีกที่นึง โดยใส่[$i]
เข้าไป
Code (PHP)
for($i=0;$i<$_POST["totalprocess"];$i++)
{
$strSQL = "INSERT INTO process_quantity ";
$strSQL .="(team_id, product_id , process_id , process_quantity , date) ";
$strSQL .="VALUES ";
$strSQL .="('".$_POST["lstteam"]."','".$_POST["txtproductname"]."','".$_POST['process_idhid'][$i]."','".$_POST['quantity'][$i]."','". $_POST["date"]."') " ;
ขอบคุณครับที่เข้ามาช่วยแนะนำ
|
 |
 |
 |
 |
Date :
2012-08-01 09:20:24 |
By :
numaca |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แจ่มครับ
|
 |
 |
 |
 |
Date :
2012-08-01 20:58:18 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|