【发布时间】:2016-05-20 09:40:13
【问题描述】:
我正在用 Angular 构建一个项目,我有一个 html 表单,可以将数据发送到 MYSQL 中的“客户”表。现在我想显示“客户”表的数据。这是我试图获取该数据但它不起作用的代码。谁能帮忙?
php代码:
<?php
$con = mysqli_connect('localhost','root','','hamatkin');
if(!$con){
die("couldnt connect".mysqli_error);
}
$query = "SELECT * FROM customers";
$result = $con->query($query);
$r = array();
if( $result->num_rows>0){
while($row = $result->fetch_assoc()){
$r[] = $row;
}
}
$res = json_encode($r);
echo $res;
echo $sql_statement;
?>
控制器:
"use strict";
var app = angular.module('dataSystem',[]);
app.controller('customerCardsCtrl',function($scope,$route,$location,$http){
$http({method:'GET', url:'api/get-allCustomers.php'}).success(function(response){
$scope.customers = response.data;
});
});
});
html代码:
<!DOCTYPE html>
<html >
<head>
<title></title>
</head>
<body>
<div>
<table ng-controller="customerCardsCtrl" >
<tr ng-repeat="x in customers">
<td> {{ x.customer_id}} </td>
<td>{{ x.first_name }}</td>
<td>{{ x.last_name }}</td>
<td> {{ x.id}} </td>
<td> {{ x.city}} </td>
<td> {{ x.adress}} </td>
<td> {{ x.phone}} </td>
<td> {{ x.email}} </td>
<td> {{ x.fax}} </td>
<td> {{ x.referrer}} </td>
<td> {{ x.comments}} </td>
</tr>
</table>
</div>
</body>
</html>
【问题讨论】:
-
你遇到了什么错误?
-
html 页面没有显示数据并且保持不变
-
你在 php 端打印 2 个 json。请删除不正确的 1。
-
phpMyAdmin是一个用 PHP 编写的工具MYSQL是一个 DBMS -
你能说得更具体点吗?