0

I have a controller declared and I was loading the data from a json file. THat was working fine, so I decided to create a database and a php file to do a select and retrieve the data from the table I am storing it.

The data from php is retrieved on json, this is my code on php:

<?php
$con = mysqli_connect("127.0.0.1", "root", "", "peopledir");
// Check connection
if (mysqli_connect_errno()) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$result = mysqli_query($con, "SELECT * FROM people");
$rows = array();

while ($row = mysqli_fetch_array($result)) {
    $rows[] = $row;
}

print json_encode($rows);

mysqli_close($con);
?>

It retrieves this:

[{"0":"1","id":"1","1":"Santiago","name":"Santiago"}]

My controller is:

'use strict';

/* Controllers */

var myApp = angular.module('myApp');


myApp.controller('PeopleController', function($scope, $http) {

$http.get('http://localhost').success(function(data) {
    $scope.peoples = data;
  });

});

But it is not showing any data on the frontend.

To be clear, if I paste the data to a json file, exactly as php is showing it, I can see the user Santiago on the page, but with above code, reading directly from http://localhost, I can not see anything.

Thanks

1
  • Have you looked at my answer? Commented Mar 3, 2014 at 21:00

1 Answer 1

1

You should use mysqli_fetch_assoc:

while ($row = mysqli_fetch_assoc($result)) {
    $rows[] = $row;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.