即時通訊建設一個項目,我有一個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頁面不顯示數據,並保持不變 –
你打印2 PHP的方面json。請刪除不正確的1。 –