I'm wanting to load list of names from SQL DB. I then want to click the name and have corresponding image load. The first image should load when page loads. Names are loading. Image is not loading and ng-click does not load image. Made similar code work using JSON, but not able to make work using DB. Cats is the name of table. ImagePath and CatName are the fields in DB. New to PHP. Thank you.
<!doctype html>
<html>
<head>
<title>Load Images from DB</title>
<script src="angular.min.js"></script>
</head>
<body ng-app='myapp'>
<div ng-controller="userCtrl">
<div ng-repeat="user in Cats">
<h3 ng-click = "$scope.selectCat(cat)">{{user.CatName}}</h3>
</div>
<img ng-src="{{$scope.selectedCat.ImagePath}}"/>
<!-- Script -->
<script>
var fetch = angular.module('myapp', []);
fetch.controller('userCtrl', ['$scope', '$http', function ($scope, $http) {
$http({
method: 'get',
url: 'getData.php'
}).then(function successCallback(response) {
$scope.Cats = response.data;
$scope.selectCat=selectCat;
$scope.selectedCat=$scope.Cats[0];
function selectCat(pos) {
$scope.selectedCat = pos;
};
});
}]);
</script>
</div>
</body>
</html>
Here is PHP code
include 'config.php';
$sel = mysqli_query($con,"select * from Cats");
$data = array();
while ($row = mysqli_fetch_array($sel)) {
$data[] = array("CatName"=>$row['CatName'],"ImagePath"=>$row['ImagePath']);
}
echo json_encode($data);