สวัสดีครับพี่ๆ พอดีว่าผมทำ todo-list ตอนนี้ผมติดตรงที่ ผมต้องการ insert ข้อมูลที่เป็น array ครับ ผมควรเขียนประมาณไหนครับ พี่ๆ ช่วยชี้เเนะด้วยครับผม
โค้ดส่วนของ หน้า todo-list ครับ
// js
var element_html = 1;
$('#btn-add-todolist').click(function(e) {
e.preventDefault();
let html_tbody = ``;
for (let i = 1; i < element_html; i++) {
html_tbody = `
<tr id="tr${i}">
<td>${i}<input type="hidden" id="number" name="number[]" value="${i}"></td>
<td><input type="date" class="form-control" id="taxinput_datestart" name="taxinput_datestart[]"></td>
<td>
<div class="form-floating">
<textarea class="form-control" id="taxinput_number" name="taxinput_number[]" style="height: 40px"></textarea>
</div>
</td>
<td>
<select class="custom-select form-control" id="taxinput_buyername" name="taxinput_buyername[]" tabindex="2">
<option value="">ชื่อผู้ซื้อ/ผู้รับบริการ...</option>
<?php foreach ($arr_test as $key => $val) : ?>
<option value="<?= $val['name']; ?>"><?= $val['name']; ?></option>
<?php endforeach; ?>
</select>
</td>
<td>
<div class="form-floating">
<textarea class="form-control" id="taxinput_orderlist" name="taxinput_orderlist[]" style="height: 40px"></textarea>
</div>
</td>
<td><input type="text" class="form-control" id="taxinput_productvalue" name="taxinput_productvalue[]"></td>
<td><input type="text" class="form-control" id="taxinput_vat" name="taxinput_vat[]"></td>
<td><input type="text" class="form-control" id="taxinput_sum" name="taxinput_sum[]"></td>
<td><button type="button" class="btn btn-outline-danger" onclick="btn_delete_row_todoList(${i})">
<svg xmlns="
http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" class="bi bi-x-square-fill mb-1" viewBox="0 0 16 16">
<path d="M2 0a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2H2zm3.354 4.646L8 7.293l2.646-2.647a.5.5 0 0 1 .708.708L8.707 8l2.647 2.646a.5.5 0 0 1-.708.708L8 8.707l-2.646 2.647a.5.5 0 0 1-.708-.708L7.293 8 4.646 5.354a.5.5 0 1 1 .708-.708z"/>
</svg></button>
</td>
</tr>
`;
}
$('#display-todolist').append(html_tbody);
element_html++;
});
// php
// array output
Array
(
[taxinput_buyername] => Array
(
[0] => alex
[1] => joe
)
[taxinput_orderlist] => Array
(
[0] => qq
[1] => qq
)
[taxinput_datestart] => Array
(
[0] => 2022-07-22
[1] => 2022-07-22
)
[taxinput_productvalue] => Array
(
[0] => 10
[1] => 10
)
[taxinput_vat] => Array
(
[0] => 20
[1] => 30
)
[taxinput_sum] => Array
(
[0] => 20
[1] => 50
)
)
// ผลลัพท์ ในฐานข้อมูล ที่ผมอยากได้ครับ
| taxinput_buyername | taxinput_orderlist | taxinput_datestart | taxinput_orderlist | taxinput_productvalue | taxinput_vat | taxinput_sum |
alex qq 2022-07-22 qq 10 10 20
joe qq 2022-07-22 qqq 20 30 50
PHP - todo-list - insert ข้อมูล array
โค้ดส่วนของ หน้า todo-list ครับ
// js
var element_html = 1;
$('#btn-add-todolist').click(function(e) {
e.preventDefault();
let html_tbody = ``;
for (let i = 1; i < element_html; i++) {
html_tbody = `
<tr id="tr${i}">
<td>${i}<input type="hidden" id="number" name="number[]" value="${i}"></td>
<td><input type="date" class="form-control" id="taxinput_datestart" name="taxinput_datestart[]"></td>
<td>
<div class="form-floating">
<textarea class="form-control" id="taxinput_number" name="taxinput_number[]" style="height: 40px"></textarea>
</div>
</td>
<td>
<select class="custom-select form-control" id="taxinput_buyername" name="taxinput_buyername[]" tabindex="2">
<option value="">ชื่อผู้ซื้อ/ผู้รับบริการ...</option>
<?php foreach ($arr_test as $key => $val) : ?>
<option value="<?= $val['name']; ?>"><?= $val['name']; ?></option>
<?php endforeach; ?>
</select>
</td>
<td>
<div class="form-floating">
<textarea class="form-control" id="taxinput_orderlist" name="taxinput_orderlist[]" style="height: 40px"></textarea>
</div>
</td>
<td><input type="text" class="form-control" id="taxinput_productvalue" name="taxinput_productvalue[]"></td>
<td><input type="text" class="form-control" id="taxinput_vat" name="taxinput_vat[]"></td>
<td><input type="text" class="form-control" id="taxinput_sum" name="taxinput_sum[]"></td>
<td><button type="button" class="btn btn-outline-danger" onclick="btn_delete_row_todoList(${i})">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" class="bi bi-x-square-fill mb-1" viewBox="0 0 16 16">
<path d="M2 0a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2H2zm3.354 4.646L8 7.293l2.646-2.647a.5.5 0 0 1 .708.708L8.707 8l2.647 2.646a.5.5 0 0 1-.708.708L8 8.707l-2.646 2.647a.5.5 0 0 1-.708-.708L7.293 8 4.646 5.354a.5.5 0 1 1 .708-.708z"/>
</svg></button>
</td>
</tr>
`;
}
$('#display-todolist').append(html_tbody);
element_html++;
});
// php
// array output
Array
(
[taxinput_buyername] => Array
(
[0] => alex
[1] => joe
)
[taxinput_orderlist] => Array
(
[0] => qq
[1] => qq
)
[taxinput_datestart] => Array
(
[0] => 2022-07-22
[1] => 2022-07-22
)
[taxinput_productvalue] => Array
(
[0] => 10
[1] => 10
)
[taxinput_vat] => Array
(
[0] => 20
[1] => 30
)
[taxinput_sum] => Array
(
[0] => 20
[1] => 50
)
)
// ผลลัพท์ ในฐานข้อมูล ที่ผมอยากได้ครับ
| taxinput_buyername | taxinput_orderlist | taxinput_datestart | taxinput_orderlist | taxinput_productvalue | taxinput_vat | taxinput_sum |
alex qq 2022-07-22 qq 10 10 20
joe qq 2022-07-22 qqq 20 30 50