[英]Insert array of data in Database using MySQL,PHP and angular.js
[英]How to insert value in multiple row by a single user submit using PHP,Angular.js and MySQL
我需要使用Angular.js和PHP在單個用戶單擊中插入多行。 首先,我在下面解釋我的代碼。
為time.html
<table class="table table-bordered table-striped table-hover" id="dataTable">
<tr>
<td width="100" align="center">Time <i class="fa fa-long-arrow-right"></i>
<br>Day <i class="fa fa-long-arrow-down"></i>
</td>
<td width="100" align="center" ng-repeat="hour in hours" ng-bind="hour.time_slot"></td>
</tr>
<tbody id="detailsstockid">
<tr ng-repeat="days in noOfDays">
<td width="100" align="center" style=" vertical-align:middle" ng-bind="days.day"></td>
<td width="100" align="center" style="padding:0px;" ng-repeat="hour in hours">
<table style="margin:0px; padding:0px; width:100%">
<tr>
<td>
<select id="coy" name="coy" class="form-control" ng-model="sub_name " ng-options="sub.name for sub in listOfSubjectName track by sub.value">
</select>
</td>
</tr>
<tr>
<td>
<select id="coy" name="coy" class="form-control" ng-model="fac_name " ng-options="fac.name for fac in listOfFacultyName track by fac.value">
</select>
</td>
</tr>
</td>
</table>
</td>
</tr>
</tbody>
</table>
上面的代碼部分在UI上提供了以下輸出。 單擊下面的鏈接查看輸出圖像。
timecontroller.js
$http({
method: 'GET',
url: "php/timetable/gethour.php",
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
}).then(function successCallback(response){
//console.log('hour',response.data);
$scope.hours=response.data;
},function errorCallback(response) {
});
$http({
method: 'GET',
url: "php/timetable/getdays.php",
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
}).then(function successCallback(response){
$scope.days=response.data;
// console.log('days',$scope.days);
for (var i = 0; i < 5; i++) {
$scope.noOfDays.push($scope.days[i]);
}
},function errorCallback(response) {
});
在上圖中,您可以看到我有5天的時間和一些時隙。 我需要在這里,當用戶單擊任何提交按鈕時,所有選定的課程名稱數據,教員名稱數據,日時段將保存在數據庫中。 讓我舉一個例子。 假設用戶單擊第一行中的“提交”按鈕,它將再次保存monday,10AM :: 11AM,course name,faculty name
monday,09AM :: 10AM,course name,faculty name
。第二行中,它將保存monday,10AM :: 11AM,course name,faculty name
等。 這樣,它將一鍵插入5*7=35
行。 請幫我做到這一點。
當我查看您的代碼時,我看到您將選擇框綁定到“ sub_name”和“ fac_name”。 我還沒有測試過,但是我認為更改一個“ sub_name”將更新所有“ sub_name”選擇項,因為它們都綁定到相同的模型。
首先,您需要解決這個問題。 我將創建一個大模型(稱為“花名冊”),並在該模型中設置每一天/同日休。
var roster = {
monday:[
{
startTime: 9,
endTime: 10,
cource: 'courcename',
faculty: 'faculty name'
},
{
startTime: 10,
endTime: 11,
cource: 'courcename2',
faculty: 'faculty name2'
},
.......
]
}
比您可以觀察此模型,並在模型更改時執行http調用來更新數據庫。 您還可以找出實際更改的值,然后僅將這些更改推送到數據庫。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.