简体   繁体   English

使用MySQL,PHP和angular.js在数据库中插入数据数组

[英]Insert array of data in Database using MySQL,PHP and angular.js

I need one help for inserting array of data into database using PHP,MySQL and angular.js.Let me to explain my code.Suppose i have the below set of data which will insert into database. 我需要一个使用PHP,MySQL和angular.js将数据数组插入数据库的帮助。让我解释一下我的代码。假设我具有以下将插入数据库的数据集。

$scope.listOfData=[
    0:{'name':raj,'email':raj@gmail.com,'rollno':11,'subject`:abc},
    1:{'name':raja,'email':raja@gmail.com,'rollno':13,'subject`:ab},
    2:{'name':raja1,'email':raja1@gmail.com,'rollno':113,'subject`:anb},
    ....................................................................
    .....................................................................

    20:{'name':raja1,'email':raja1@gmail.com,'rollno':113,'subject`:anb},
];

I have 20 numbers of data in one object and i have only 4 field in database ( ie-name,email,rollno,subject ).When user will click on submit button these 20 nos of data will insert in DB in 20 rows.Here i need how it can be done in php. 我在一个对象中有20个数据并且数据库中只有4个字段( ie-name,email,rollno,subject )。当用户单击ie-name,email,rollno,subject按钮时,这20个数据将在20行中插入DB。我需要如何在php中完成。 In this below code i am declaring the submit function. 在下面的代码中,我声明了Submit函数。

$scope.addData=function(){
   $http({
        method:'POST',
        url: "php/timetable/addTimeTable.php",
        data:$scope.listOfTimeData,
        headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
    }).then(function successCallback(response){
        //Success callback
    },function errorCallback(response) {
        //Error callback
    });
};

Here i need how i will pass the all data to php file and insert all data in Mysql ( Lets say table name-db_user ) DB at a time in a loop.Please help me. 在这里我需要如何将所有数据传递到php文件并将所有数据一次Lets say table name-db_user插入Mysql(可以Lets say table name-db_user )DB中。请帮助我。

Format of your $scope.listOfData is invalid. $scope.listOfData格式无效。 it should be like 它应该像

$scope.listOfData=[
{'name':raj,'email':raj@gmail.com,'rollno':11,'subject`:abc},
{'name':raja,'email':raja@gmail.com,'rollno':13,'subject`:ab},
{'name':raja1,'email':raja1@gmail.com,'rollno':113,'subject`:anb},
....................................................................
.....................................................................

{'name':raja1,'email':raja1@gmail.com,'rollno':113,'subject`:anb},
];

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

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