【发布时间】:2020-04-25 21:58:10
【问题描述】:
我一直在尝试为我的 covid-19 时间通行证学习一些 SQL,并且我设法制作了数据,但我现在被困住了,我不知道如何用 angular 重复我得到的表格从我的 SQL DB 在下面的表中!,我查看了 W3School 和其他几个网站,但我没有得到它。
PHP
if($connectServer->connect_error){
die("Connection failed :".$connectServer->connection_error);
}
$result = $connectServer->query("SELECT * FROM Users");
$outp = "";
while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
if ($outp != "") {$outp .= ",";}
$outp .= '{"ID":"' . $rs["userID"] . '",';
$outp .= '"First Name":"' . $rs["FName"] . '",';
$outp .= '"Last Name":"' . $rs["FName"] . '",';
$outp .= '"City":"' . $rs["City"] . '",';
$outp .= '"Email":"'. $rs["Email"] . '"}';
}
$outp ='{"names":['.$outp.']}';
echo($outp);?>
HTML
<table ng-controller="customersCtrl" ng-app="myApp">
<tr>
<th>ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>City</th>
<th>Email</th>
</tr>
<tr ng-repeat="a in names">
<td>{{a.ID}}</td>
<td>{{a.First Name}}</td>
<td>{{a.LName}}</td>
<td>{{a.City}}</td>
<td>{{a.Email}}</td>
</tr>
</table>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<script>
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
$http.get("php/fetchDATA.php")
.then(function (response) {$scope.names = response.data.records;});
});
</script>
fetchDATA.PHP
{"names":[{"ID":"32","First Name":"ValueFName","Last Name":"ValueFName","City":"ValueCity","Email":"ValueEmail "},{"ID":"33","First Name":"ValueFName","Last Name":"ValueFName","City":"ValueCity","Email":"ValueEmail"},{"ID ":"34","First Name":"ValueFName","Last Name":"ValueFName","City":"ValueCity","Email":"ValueEmail"}]}
【问题讨论】: