2016-05-20 29 views
0

即時通訊建設一個項目,我有一個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> 
+0

你面臨什麼錯誤? –

+0

的HTML頁面不顯示數據,並保持不變 –

+0

你打印2 PHP的方面json。請刪除不正確的1。 –

回答

0

使用這個代碼,而不是

"use strict"; 
var app = angular.module('dataSystem',[]); 
app.controller('customerCardsCtrl',function($scope,$route,$location,$http){ 
    $http({method:'GET', url:'api/get-allCustomers.php'}) 
    .then(function(response){ 
      $scope.customers = response.data; 
     }, function(response){ 
      console.log(response) 
     }); 
}); 
+0

控制檯顯示我:警告試圖加載角度不止一次,並且:script1002:語法錯誤customerCardsCtrl.js(8,1)和:error: [ng:areq]參數'customerCardsCtrl'不是函數undefined –

+0

你刪除了那個額外的});你添加了嗎? –

+0

我不得不離開額外的}):因爲沒有它,頁面無法正常工作 –

相關問題