简体   繁体   English

如何使用PHP,Angular.js和MySQL由单个用户提交的多行插入值

[英]How to insert value in multiple row by a single user submit using PHP,Angular.js and MySQL

I need to insert multiple rows in a single user click using Angular.js and PHP. 我需要使用Angular.js和PHP在单个用户单击中插入多行。 First I am explaining my code below. 首先,我在下面解释我的代码。

time.html 为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>

The above part of code is giving the following output on the UI. 上面的代码部分在UI上提供了以下输出。 Click on below link see the output image. 单击下面的链接查看输出图像。

Time table 时间表

timecontroller.js 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) {
 });

In the above image, you can see I have 5 days and some time slot. 在上图中,您可以看到我有5天的时间和一些时隙。 I need here when user will click on any submit button all selected course name data, faculty name data, day time slot will save in database. 我需要在这里,当用户单击任何提交按钮时,所有选定的课程名称数据,教员名称数据,日时段将保存在数据库中。 Let me to given one example. 让我举一个例子。 Suppose user clicked on submit button in first row it will save monday,09AM :: 10AM,course name,faculty name again in second row it will save monday,10AM :: 11AM,course name,faculty name and so on. 假设用户单击第一行中的“提交”按钮,它将再次保存monday,10AM :: 11AM,course name,faculty name monday,09AM :: 10AM,course name,faculty name 。第二行中,它将保存monday,10AM :: 11AM,course name,faculty name等。 Like this way it will insert 5*7=35 row in one click. 这样,它将一键插入5*7=35行。 Please help me to do this. 请帮我做到这一点。

When I look at your code I see you bind the select boxes to "sub_name" and "fac_name". 当我查看您的代码时,我看到您将选择框绑定到“ sub_name”和“ fac_name”。 I haven't tested it, but I think changing one "sub_name" will update all of the "sub_name" select's, as they are all bound to the same models. 我还没有测试过,但是我认为更改一个“ sub_name”将更新所有“ sub_name”选择项,因为它们都绑定到相同的模型。

First you will need to tackle this. 首先,您需要解决这个问题。 I would make one big model (called "roster") and have each day/simeslot in that model. 我将创建一个大模型(称为“花名册”),并在该模型中设置每一天/同日休。

var roster = {
    monday:[
        {
            startTime: 9, 
            endTime: 10, 
            cource: 'courcename',
            faculty: 'faculty name'
        },
        {
            startTime: 10, 
            endTime: 11, 
            cource: 'courcename2',
            faculty: 'faculty name2'
        },
        .......
    ]
}

Than you can watch this model, and when it changes do your http calls to update the DB. 比您可以观察此模型,并在模型更改时执行http调用来更新数据库。 You could also figure out what values actually changed and only push these changes to the database. 您还可以找出实际更改的值,然后仅将这些更改推送到数据库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM