1

I am new to angular and getting it to work with php so bear with me. I was successful in saving data to the db with php. Now i want to retrieve it and show it in a list. The data is coming back from the DB but its not showing in my view (html)

my html code is:

<!-- Show users from db -->
<div>
    <ul ng-init="get_user()">
        <li ng-repeat="user in userInfo track by $index">{{user.user_name}} + {{user.user_email}}</li>
    </ul>
</div>
<!-- Show users from db -->

The code of my app.js is this:

/** function to get info of user added in mysql referencing php **/
$scope.get_user = function() {
    $http.get('db.php?action=get_user').success(function(data)
    {
        $scope.userInfo = data;   
        console.log("You were succesfull in show user info"); 
        console.log(data);
    })
}

And finally my php code:

/**  Function to get a user   **/
function get_user() {    
    $qryGet = mysql_query('SELECT * from tblUser');

    echo ($qryGet);

    $data = array();
    while($rows = mysql_fetch_array($qryGet))
    {
        $data[] = array(
                    "id"            => $rows['id'],
                    "user_name"     => $rows['user_name'],
                    "user_email"    => $rows['user_email']
                    );
    }

    print_r(json_encode($data));

    return json_encode($data);  
}

When running it in the browser i get this in my console. (http://gyazo.com/4621faa287a041ed9f7f610552407e9f). Any clues are welcome

2

1 Answer 1

1

That's because your data is not

[{"id":"1", "user_name":"Foo Bar" ... }]

It's:

Connected to the DBResource id #4[{"id":"1", "user_name":"Foo Bar" ... }]

You can see it in the console log. Remove the line that says

echo ($qrtGet);

In your php

Sign up to request clarification or add additional context in comments.

2 Comments

ok the correct echo of -> each($qrtGet) is Resource id #4. the Connect to DB was the echo of my succesfull connection to the db. when delete this echo i still get the same issue ...
for those who might have the same issue as me in the future, i just commented my echo($qryGet) and then it worked

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.