 |
ถามเรื่อง text field บันทึกลงฐานข้อมูลพร้อมกันหลายๆfield จะเขียนโค้ดยังไง |
|
 |
|
|
 |
 |
|
ลอง ใช้ array ดู
|
 |
 |
 |
 |
Date :
2009-04-20 13:00:37 |
By :
jiro_aaron |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้าจะใช้ array จะเขียนโค้ดยังไง ที่แบบว่าให้มันเพิ่ม text field ได้อีกไปเรื่อย แล้วก็บันทึกพร้อมกัน
ขอความอนุเคราะห์ด้วยน่ะครับ
|
 |
 |
 |
 |
Date :
2009-04-20 13:13:10 |
By :
wiroon152 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
html
<input type="text" name="decription_n[]">
<input type="text" name="unit[]">
<input type="text" name="quantity[]">
<input type="text" name="price_unit[]">
<input type="text" name="amount[]">
insert php
<?php
for($i=0;$i<count($_POST["decription_n"]);$i++)
{
$sql = "insert into __table__ (decription_n, unit,quantity,price_unit,amount) values ('decription_n[$i]', 'unit[$i]','quantity[$i]', 'price_unit[$i]','amount[$i]')";
mysql_query($sql) or die(mysql_error());
}
?>
|
 |
 |
 |
 |
Date :
2009-04-20 13:18:56 |
By :
GhostLocal |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ยังไม่เข้าใยเลย
<input type="text" name="decription_n[]">
<input type="text" name="unit[]">
<input type="text" name="quantity[]">
<input type="text" name="price_unit[]">
<input type="text" name="amount[]">
ข้างใน [] จะต้องใส่ อะไรหรือป่าว
|
 |
 |
 |
 |
Date :
2009-04-20 13:47:06 |
By :
wiroon152 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่ต้องใส่ครับแบบนั้นเลย
|
 |
 |
 |
 |
Date :
2009-04-20 16:27:37 |
By :
GhostLocal |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองทำความเข้าใจ ลิงค์ที่พี่วินให้มานะครับ ย้ำว่าทำความเข้าใจก่อน มันไม่ยากอย่างที่คิด
|
 |
 |
 |
 |
Date :
2009-04-20 16:35:55 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ยังไม่เข้าใยเลย
<input type="text" name="decription_n[]">
<input type="text" name="unit[]">
<input type="text" name="quantity[]">
<input type="text" name="price_unit[]">
<input type="text" name="amount[]">
ข้างใน [] จะต้องใส่ อะไรหรือป่าว
- - - - - - - - - - - - - - - - -
อธิบายเพิ่มครับ name="decription_n[]" หมายความว่าตัวแปร decription_n ตั้งเป็น ตัวแปร array
เวลาจะไปใช้งาน ถ้ามีข้อมูลหลายเรคคอร์ด มันก็จะเก็บในตัวแปร decription_n[0] decription_[1]
เองโดยอัตโนมัติ โค๊ตที่ ความเห็นที่ 3 ให้ไป count($_POST["decription_n"]) หมายความว่า
ให้ดูว่า decription_n มันเป็น array ขนาดเท่าไหร่ หมายถึงว่ามันมีกี่ เรคคอร์ด แต่ array มันเริ่มที่ 0 โค๊ตเลยเป็น for($i=0;$i<count($_POST["decription_n"]);$i++) ให้เริ่มจาก 0 จนถึง ขนาดของ array ถ้า array มันมีขนาด 5 เรคคอร์ด แสดงว่า ต้องวนลูป 0-4 $i เลยต้อง < count($_POST["decription_n") อธิบายแบบนี้น่าจะพอเข้าใจมากขึ้นนะครับ
|
 |
 |
 |
 |
Date :
2009-04-20 16:43:45 |
By :
volvojedi |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แบบนี้ แนวคิดจะคล้าย ๆ กับเว็บบรอด น้าเราว่า แต่แบบนี้จะยากกว่านีสนึงเพราะเป็นการเพิ่มทีละหลายรายการอะ
|
 |
 |
 |
 |
Date :
2009-04-20 22:52:55 |
By :
jiro_aaron |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อิอิ
|
 |
 |
 |
 |
Date :
2010-09-28 17:45:14 |
By :
- |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณค่ะ เป็นประโยชน์อย่างมากเลยค่ะ
|
 |
 |
 |
 |
Date :
2011-12-15 22:32:52 |
By :
soon |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|