I am trying to use the slim php framework as a restful backend to an angular frontend. I'm having problems fetching all records from my sql database. I am using the following code in my controller:
function refreshlistings() {
Data.get('getAllListings').then(function(results) {
$scope.lists = results;
var tempdata;
for (var i = 0; i < $scope.lists.length; i++) {
$scope.lists[i].data = decrypt($scope.lists[i].data);
}
if (!$scope.lists) {
$scope.lists = [];
}
});
}
in my factory:
obj.get = function(q) {
return $http.get(serviceBase + q).then(function(results) {
return results.data;
});
};
And my slim API looks like this:
$app->get('/getAllListings', function(){
$db = new DbHandler();
$listings = array();
$listings = $db->getAllRecords("select * from LISTINGTABLE");
echoResponse(200, $listings);
});
in my DbHandler class:
public function getAllRecords($query) {
$r = $this->conn->query($query) or die($this->conn->error.__LINE__);
return $result = $r->fetch_assoc();
}
I am only getting back one record from my SQL.
I tried:
public function getAllRecords($query) {
$r = $this->conn->query($query) or die($this->conn->error.__LINE__);
while ( $row = $r->fetch_array(MYSQLI_ASSOC) ) {
$data[] = $row;
}
return $data[];
}
In my DbHandler class, but that gives me an error. Can anyone help me out? thx!