|
|
|
สอบถามครับ ทำไม ใช้ foreach loop ใส่ใน sql ได้ เเต่ได้เเค่ 4 เเถวเองครับ ได้ไม่หมด |
|
|
|
|
|
|
|
Code (PHP)
echo count($_POST);
//หรือ
print_r($_POST);
น่าจะทำให้รู้จัก คุณสมบัติ ของตัวแปรดีขึ้น
|
|
|
|
|
Date :
2016-09-13 06:30:39 |
By :
Chaidhanan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
มันทำการ foreach ได้มาเป็น 4 ครัง เเบบนี้ ผมจะต้องทำไงต่อครับ
4
Array ( [0] => 1.s [1] => 2.s [2] => 3.s [3] => 4.s [4] => 5.s [5] => 6.s [6] => 7.s [7] => 8.s [8] => 9.s [9] => 10.s )
Array ( [0] => 1.h [1] => 2.h [2] => 3.h [3] => 4.h [4] => 5.h [5] => 6.h [6] => 7.h [7] => 8.h [8] => 9.h [9] => 10.h )
4
Array ( [0] => 1.s [1] => 2.s [2] => 3.s [3] => 4.s [4] => 5.s [5] => 6.s [6] => 7.s [7] => 8.s [8] => 9.s [9] => 10.s )
Array ( [0] => 1.h [1] => 2.h [2] => 3.h [3] => 4.h [4] => 5.h [5] => 6.h [6] => 7.h [7] => 8.h [8] => 9.h [9] => 10.h )
4
Array ( [0] => 1.s [1] => 2.s [2] => 3.s [3] => 4.s [4] => 5.s [5] => 6.s [6] => 7.s [7] => 8.s [8] => 9.s [9] => 10.s )
Array ( [0] => 1.h [1] => 2.h [2] => 3.h [3] => 4.h [4] => 5.h [5] => 6.h [6] => 7.h [7] => 8.h [8] => 9.h [9] => 10.h )
4
Array ( [0] => 1.s [1] => 2.s [2] => 3.s [3] => 4.s [4] => 5.s [5] => 6.s [6] => 7.s [7] => 8.s [8] => 9.s [9] => 10.s )
Array ( [0] => 1.h [1] => 2.h [2] => 3.h [3] => 4.h [4] => 5.h [5] => 6.h [6] => 7.h [7] => 8.h [8] => 9.h [9] => 10.h )
|
|
|
|
|
Date :
2016-09-13 08:00:13 |
By :
tongar |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
if (isset($_POST['add1'])) {
$count = count($_POST['id']);
for ($i = 0; $i < $count; $i++) {
$sql = $sql="UPDATE assessment_kpi SET score='".$_POST['score'][$i]."', head='".$_POST['head'][$i]."' where id_kpi='".$_POST['id'][$i]."' ";
mysql_query($sql, $link);
}
}
|
|
|
|
|
Date :
2016-09-13 08:33:09 |
By :
fossil31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 score
2 head
3 id
4 add1
|
|
|
|
|
Date :
2016-09-13 08:35:57 |
By :
-..- |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ได้เเล้วครับ ขอบคุณครับ
|
|
|
|
|
Date :
2016-09-13 08:37:46 |
By :
tongar |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เปลี่ยนมาใช้ตัวนี้เเทน ของคุณครับ คุณ fossil
Code (PHP)
if (isset($_POST['add1'])) {
$count = count($_POST['id']);
for ($i = 0; $i < $count; $i++) {
$sql = $sql="UPDATE assessment_kpi SET score='".$_POST['score'][$i]."', head='".$_POST['head'][$i]."' where id_kpi='".$_POST['id'][$i]."' ";
mysql_query($sql, $link);
}
}
แต่จริงๆ foreach ไม่หน้ามีปัณหา ดันได้เเค่ 4ครั้ง
|
|
|
|
|
Date :
2016-09-13 08:42:56 |
By :
tongar |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
element ของ $_POST มันมี แค่ 4 ตามนี้
1 score
2 head
3 id
4 add1
element ของ $_POST['id'] มีตามจำนวนที่คุณทำ
แค่อ้างอิงตัวแปรผิดเพราะยังเข้าใจเรื่องตัวแปร array ไม่ดีพอ ดังนั้นทำความเข้าใจตัวแปร array ให้มากกว่านี้
|
|
|
|
|
Date :
2016-09-13 09:10:54 |
By :
Chaidhanan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|