これは、テーブル内に動的行を追加しているメイン ページです (jQuery がこれを実行しています)。追加する行数が 'n' であるため、すべての動的数の行 (4 つの異なるテキスト フィールド) に対して SQL 挿入ステートメントを実行するにはどうすればよいですか? .
Simpleでは、Insertステートメントの値として(1,2,3,x,y,z)要素があります.x、y、zは任意の数の行にすることができます(ただし、x、y、zは常に等しい数になります)の要素)、1,2,3 とともに、この x、y、z の配列を追加する必要があります。INSERT ステートメント内の FOR ループは、google n stackOverflow から取得したものですが、1,2,3 (事前定義された要素) とともに 4 つの異なるテキストフィールドを FOR ループするにはどうすればよいですか?
よりシンプルに-
(value1,value2,value3,x,y,z);
(value1,value2,value3,a,b,c);
(value1,value2,value3,e,f,g);
(value1,value2,value3,q,w,e);
(value1,value2,value3,a,s,d);
これを MySQL の単一の INSERT ステートメント内に挿入するにはどうすればよいですか?
<html>
<head>
<script src="http://code.jquery.com/jquery-1.5.1.min.js"></script>
<script src="jquery.json-2.4.min.js"></script>
<script>
$(document).ready(function() {
var id = 0;
// Add button functionality
$("table.dynatable button.add").click(function() {
id++;
var master = $(this).parents("table.dynatable");
// Get a new row based on the prototype row
var prot1= master.find(".prototype").clone();
prot1.attr("class", "")
prot1.find(".id").attr("value", id);
master.find("tbody").append(prot1);
alert(id);
});
// Remove button functionality
$("table.dynatable button.remove").live("click", function() {
$(this).parents("tr").remove();
});
//Submit button clicked
$('#button').click(function() {
//$("table tr").has("th").remove();
var data = {
value : []
}
$("table tbody tr").each(function() {
data.value.push($('.id', this).val());
data.value.push($('.WID', this).val());
data.value.push($('.ac', this).val());
data.value.push($('.tm', this).val());
data.value.push($('.cutt', this).val());
});
console.log(data);
var id = data.value.join(','); alert(id);
var myarr1={final:data};
var myarr2=JSON.stringify(myarr1);
var myarr3="receivearray.php?url=" + encodeURIComponent(myarr2);
$('#myFrame1').attr("src", myarr3);
});
});
</script>
<style>
.dynatable {
border: solid 1px #000;
border-collapse: collapse;
}
.dynatable th,
.dynatable td {
border: solid 1px #000;
padding: 2px 10px;
width: 170px;
text-align: center;
}
.dynatable .prototype {
}
</style>
</head>
<body>
<table id="MyTable" class="dynatable">
<thead>
<tr>
<th>WID</th>
<th>InchargeName</th>
<th>Action</th>
<th>Time</th>
<th><button class="add">Add</button></th>
</tr>
</thead>
<tbody>
<tr class="prototype" id="pro">
<td><input type="text" name="id[]" value="" class="id" /></td>
<td><input type="text" name="name[]" value="" class="WID"/></td>
<td><input type="text" name="col4[]" value="" class="ac" /></td>
<td><input type="text" name="col3[]" value="" class="tm"/></td>
<td><button class="remove">Remove</button>
</tr>
</table>
<input type="button" id="button" value="submit"/>
</body>
</html>