im building a project with angular,i have a html form that sends data to "customers" table in MYSQL. now i want to show the data of "customers" table. this is my code that i tried to get that data but its not working. can anyone help?
php code:
<?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;
?>
controller:
"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 code:
<!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>