ng-repeat doesn't read SQL json file results

18 views
Skip to first unread message

Andrej Batarilo

unread,
May 26, 2018, 7:29:11 PM5/26/18
to Angular and AngularJS discussion
Hello, so I prettty much copied this code and it doesn't work for me, but does for other people (the entire html and php)

When I try the query in SQL Management it works, so I don't think it's the database
When I try to read from the database it's just blank, no errors in the console

Here is my select.php:

<?php
//select.php
$connect = mysqli_connect("den1.mssql5.gear.host", "testiranje", "nijebitno@", "testiranje");
$output = array();
$query = "SELECT * FROM dbo.tbl_user";
$result = mysqli_query($connect, $query);
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{
$output[] = $row;
}
echo json_encode($output);
}
?>

Here is my html code:

<!DOCTYPE html>
<!-- index.php !-->
<html>
<head>
<title>Webslesson Tutorial | AngularJS Tutorial with PHP - Fetch / Select Data from Mysql Database</title>
</head>
<body>
<br /><br />
<div class="container" style="width:500px;">
<h3 align="center">AngularJS Tutorial with PHP - Fetch / Select Data from Mysql Database</h3>
<div ng-app="myapp" ng-controller="usercontroller" ng-init="displayData()">
<label>First Name</label>
<input type="text" name="first_name" ng-model="firstname" class="form-control" />
<br />
<label>Last Name</label>
<input type="text" name="last_name" ng-model="lastname" class="form-control" />
<br />
<input type="submit" name="btnInsert" class="btn btn-info" ng-click="insertData()" value="ADD"/>
<br /><br />
<table class="table table-bordered">
<tr>
<th>First Name</th>
<th>Last Name</th>
</tr>
<tr ng-repeat="x in names">
<td>{{x.first_name}}</td>
<td>{{x.last_name}}</td>
</tr>
</table>
</div>
</div>
</body>
</html>
<script>
var app = angular.module("myapp",[]);
app.controller("usercontroller", function($scope, $http){
$scope.insertData = function(){
$http.post(
"insert.php",
{'firstname':$scope.firstname, 'lastname':$scope.lastname}
).success(function(data){
alert(data);
$scope.firstname = null;
$scope.lastname = null;
$scope.displayData();
});
}
$scope.displayData = function(){
$scope.names = new Array;
$http.get("select.php")
.success(function(data){
console.log("sranje");
$scope.names = data;
console.log(data);

});
}
});
</script>

Lucas Lacroix

unread,
May 26, 2018, 7:33:12 PM5/26/18
to ang...@googlegroups.com
It looks like you're using the mysqli php library to connect to an mssql database. Trying debugging your php script by invoking it directly in the browser. 

--
You received this message because you are subscribed to the Google Groups "Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.
--
Lucas Lacroix
Computer Scientist
Advanced Technology Division, MEDITECH

Andrej Batarilo

unread,
May 26, 2018, 8:04:31 PM5/26/18
to Angular and AngularJS discussion
oh my god thank you so much, i feel like an idiot
Reply all
Reply to author
Forward
0 new messages