0
私は、複数のステップフォームを用意しています。私はこの情報を1つのレコードのMySQLデータベースに保存しようとしていますが、何らかの理由で配列から1項目だけを保存しています。何か案は?データベースに配列を保存
<table id="suppliestable" class="table order-list3 table-hover table-condensed table-bordered" >
<thead>
<tr>
<th width="30%">Supply Part #</th>
<th width="30%">Supply Desc.</th>
<th size="4">Supply Price</th>
<th>Supply Qty</th>
<th>Total</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="text" class="input-small2" name="supplynumber"></td>
<td><input type="text" class="input-small2" name="supplydescription" ></td>
<td><input type="text" class="input-small2" name="supplyprice" size="4" onblur="doCalc2(); calculate2();"></td>
<td><input type="text" class="input-small2" name="supplyquantity" size="4" onblur="doCalc2(); calculate2();"></td>
<td>$<span class="amount2"></span> </td>
<td><a class="deleteRow3"></a></td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="5" style="text-align: left;">
<input type="button" id="addrow3" value="Add" class="btn btn-primary" />
</td>
</tr>
</tfoot>
$(document).ready(function() {
var counter = 0;
$("#addrow3").on("click", function() {
doCalc2();
calculate2();
grandsum();
counter = $('#suppliestable tr').length - 2;
var newRow = $("<tr>");
var cols = "";
cols += '<td><input text="text" class="input-small2" name="supplynumber' + counter + '" /></td>';
cols += '<td><input text="text" class="input-small2" name="supplydescription' + counter + '"/></td>';
cols += '<td><input class="input-small2" size="4" type="text" name="supplyprice' + counter + '" onblur="doCalc2(); calculate2();"/></td>';
cols += '<td><input class="input-small2" size="4" type="text" name="supplyquantity' + counter + '" onblur="doCalc2(); calculate2();"/></td>';
cols += '<td>$<span class="amount2"></span></td>';
cols += '<td><input type="button" class="ibtnDel btn btn-danger" value="X"></td>';
newRow.append(cols);
if (counter == 100) $('#addrow3').attr('disabled', true).prop('value', "You've reached the limit");
$("table.order-list3").append(newRow);
counter++;
});
$("table.order-list3").on("click", ".ibtnDel", function (event) {
$(this).closest("tr").remove();
doCalc2();
calculate2();
grandsum();
counter -= 1
$('#addrow3').attr('disabled', false).prop('value', "Add Row");
});
});
そしてPHP:
$supplynumber = $_POST['supplynumber'];
$supplynumberarray = implode(", ", $supplynumber);
$supplydescription = $_POST['supplydescription'];
$supplydescriptionarray = implode(", ", $supplydescription);
$supplyprice = $_POST['supplyprice'];
$supplypricearray = implode(", ", $supplyprice);
$supplyquantity = $_POST['supplyquantity'];
$supplyquantityarray = implode(", ", $supplyquantity);
$partnumber = $_POST['partnumber'];
$partnumberarray = implode(", ", $partnumber);
$partdescription = $_POST['partdescription'];
$partdescriptionarray = implode(", ", $partdescription);
$partprice = $_POST['partprice'];
$partpricearray = implode(", ", $partprice);
$partquantity = $_POST['partquantity'];
$partquantityarray = implode(", ", $partquantity);
MySQLの
$result = mysqli_query($mysqli, "INSERT INTO invoices(supplynumber, supplydescription, supplyprice, supplyquantity, partnumber, partdescription, partprice, partquantity, login_id) VALUES('$supplynumberarray', '$supplydescriptionarray', '$supplypricearray', '$supplyquantityarray', '$partnumberarray', '$partdescriptionarray', '$partpricearray', '$partquantityarray', '$loginId')");
は配列 '名前= "supplynumber []"'や '名前は= "supplynumber [ '+カウンター+']"' – AbraCadaver
を使用してみてくださいそれはうまくいきました、ありがとうございます – user1235709
テーブルには実際にすべての列にコンマ区切りのリストがありますか?それはひどいデザインです。各項目は異なる行にある必要があります。 – Barmar