try to understand below code..
db.php
<?php
include '../includes/config.php';
switch ($_GET['action']) {
case 'add_product' :
add_product();
break;
case 'get_product' :
get_product();
break;
}
function get_product() {
$qry = mysql_query('SELECT * from product');
$data = array();
while ($rows = mysql_fetch_array($qry)) {
$data[] = array(
"ng_id" => $rows['ID'],
"ng_name" => $rows['Name'],
"ng_desc" => $rows['Detail'],
"ng_price" => $rows['Price'],
"ng_quantity" => $rows['Quantity']
);
}
print_r(json_encode($data));
return json_encode($data);
}
app.js
var app = angular.module('store', ["ngRoute"]);
app.controller("mainController", function ($scope, $http) {
$scope.get_product = function () {
$http.get("db.php?action=get_product").success(function (data) {
$scope.myData = data;
}).error(function () {
$scope.data = "error in fetching data";
});
};
}
index.php
//if you want to use bootstrap div structure
<div class="row" ng-repeat="x in myData">
<div class="col-md-4">{{x.ng_id}}</div>
<div class="col-md-4">{{x.ng_name}}</div>
<div class="col-md-4">{{x.ng_desc}}</div>
</div>
//if you want to use table structure
<table>
<tbody data-ng-init="get_product();">
<tr data-ng-repeat="x in myData ">
<td>{{$index}}</td>
<td>{{ x.ng_name}}</td>
<td>{{ x.ng_desc}}</td>
<td>{{ x.ng_price}}</td>
<td>{{ x.ng_quantity}}</td>
<td>
<a href="" data-ng-click="edit_product(x.ng_id)">Edit</a> |
<a href="" data-ng-click="delete_product(x.ng_id)" modal-backdrop="static">Delete</a>
</td>
</tr>
</tbody>
</table>