|
 |
|
สอบถามเรื่องเพิ่มแถวช่องว่างใน Table แบบอัตโนมัติโดนนับข้อมูลจากที่คิวรี่ก่อนว่ามีจำนวนเท่าไหร่ |
|
 |
|
|
 |
 |
|
ถ้าต้องการถึง 16 ก็สร้างต่อไปครับหลังครบลูป while ที่ดึงจากฐานข้อมูล
while($row = mysql_fetch_assoc($qry)){
$i++;
}
ถ้าค่า $i สุดท้ายคือ 5 ก็สร้างต่อให้ครบ 16 โดย
while($i < 16){
$i++;
}
while ที่ 2 นี้จะทำงานเมื่อ $i น้อยกว่า 16
|
 |
 |
 |
 |
Date :
2013-06-26 15:39:50 |
By :
{Cyberman} |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
https://www.thaicreate.com/php/php-mysql-add-insert-multiple-record.html
|
 |
 |
 |
 |
Date :
2013-06-27 16:59:43 |
By :
{Cyberman} |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่ได้อ่ะครับ ลองแล้วไม่มีอะไรเข้าฐานข้อมูลเลย
Code (PHP)
<form action="Work_print2.php" name="Print" method="POST">
<table width= "1050" border="1">
<tr>
<th width="6%" align="center">ลำดับที่ </th>
<th width="32%" align="center">รายการ </th>
<th width="8%" align="center">รหัสวัตถุดิบ</th>
<th width="22%" align="center">ปริมาณ </th>
<th width="22%" align="center">Type </th>
<th width="22%" align="center">Class </th>
<th width="10%" align="center">จำนวนที่ผลิตได้ </th>
<th width="10%" align="center">หมายเหตุ</th>
</tr>
<?
$i=0;
while($Re_SQL = mysql_fetch_array($Query))
{$i++;
?>
<tr>
<td align="center"><? echo $i; ?></td>
<td align="Left"><input readonly type="text" name="Name_M<?php echo $i;?>" value="<?php echo $Re_SQL["Name"];?>"></td>
<td align="center"><input readonly type="text" name="Code_M<?php echo $i;?>" value="<?php echo $Re_SQL["Code"];?>"></td>
<td align="Right"><input readonly type="text" name="Quantity_M<?php echo $i;?>" value="<?if ($_GET["Type_Formula"] == 1 ){echo $Re_SQL_a["Batch_size_1"];?> X <?php echo $Re_SQL["Quantity"];}else{echo '';}?>"></td>
<td align="Right"><input readonly type="text" name="Type_M<?php echo $i;?>" value="<?php echo $Re_SQL["Type"];?>"></td>
<td align="Right"><input readonly type="text" name="Class_M<?php echo $i;?>" value="<?php echo $Re_SQL["Class"];?>"></td>
<td align="Right"><input type="text" readonly name="Quantity_text_M<?php echo $i;?>" id="Quantity" value="<?php
if ($_GET["Type_Formula"] == 1 ){echo ($i === 1) ? $Re_SQL_a["Batch_size_1"].' X (100 L or 1,000 viais)' : '';}
else{echo '';}?> " /></div></td>
<td align="Left"><input type="text" name="Note_M<?php echo $i;?>" id="Note" value="" /></td>
<?
}
while($i < 16){
$i++;
?>
<tr>
<td align="center"><? echo $i; ?></td>
<td align="center"><input type="text" name="abount1<?php echo $i;?>" id="abount1" value="1" /></td>
<td align="center"><input type="text" name="abount2<?php echo $i;?>" id="abount2" value="2" /></td>
<td align="center"><input type="text" name="abount3<?php echo $i;?>" id="abount3" value="3" /></td>
<td align="center"><input type="text" name="abount4<?php echo $i;?>" id="abount4" value="4" /></td>
<td align="center"><input type="text" name="abount5<?php echo $i;?>" id="abount5" value="5" /></td>
<td align="center"><input type="text" name="abount6<?php echo $i;?>" id="abount6" value="6" /></td>
<td align="center"><input type="text" name="abount7<?php echo $i;?>" id="abount7" value="7" /></td>
</tr>
</tr>
<?
}
?>
</table>
<input type="submit" name="submit" value="submit">
<input type="hidden" name="hdnLine" value="<?=$i;?>">
</form>
Code (PHP)
for($i=1;$i<=$_POST["hdnLine"];$i++)
{
if($_POST["Name_M$i"] != "")
{
$strSQL_a = "INSERT INTO Bom
(
ID_Transaction,
Name_M,
Code_M,
Quantity_M,
Type_M,
Class_M,
Quantity_text_M,
Note_M,
abount1,
abount2,
abount3,
abount4,
abount5,
abount6,
abount7
)
VALUES
('$ID_Transaction','".$_POST["Name_M$i"]."',
'".$_POST["Code_M$i"]."',
'".$_POST["Quantity_M$i"]."',
'".$_POST["Type_M$i"]."',
'".$_POST["Class_M$i"]."',
'".$_POST["Quantity_text_M$i"]."',
'".$_POST["Note_M$i"]."',
'".$_POST["abount1$i"]."',
'".$_POST["abount2$i"]."',
'".$_POST["abount3$i"]."',
'".$_POST["abount4$i"]."',
'".$_POST["abount5$i"]."',
'".$_POST["abount6$i"]."',
'".$_POST["abount7$i"]."'
)";
$objQuery_a = mysql_query($strSQL_a);
}
}
|
ประวัติการแก้ไข 2013-06-28 11:12:06
 |
 |
 |
 |
Date :
2013-06-28 10:34:28 |
By :
cappuczino |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับ ได้ใช้เลย
|
 |
 |
 |
 |
Date :
2014-02-07 10:55:15 |
By :
aram0418 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|