PHP + Angular, help me with a simple example

0

I've never used a framework at all. I've always had it all on my nail for years. Sunday I started to see about the angle, but I'm bumping into something that should be minimal, but I can not: get data from a php file and put it in my view. Here is what I have already typed. If possible tell me some material to see how php exchanges data with angular.

index.html file

<!doctype html>
<html ng-app="myApp">
<head>
<meta charset="utf-8">
<title>Documento sem título</title>
<script src="angular.min.js"></script>
</head>

<body>

<div ng-controller="myController">
    <table>
        <tr ng-repeat="f in fornecedores">
            <td>{{f.id}}</td>
            <td>{{f.nome}}</td>
            <td>{{f.tipo}}</td>
        </tr>
    </table>
</div>

<script>
    var app = angular.module("myApp", []);

    app.controller("myController", function($scope, $http){
        $http.get("buscafornecedores.php").then(function(response){
            console.log(response.data);
        });
    });
</script>

</body>
</html>

Archive search for suppliers.php

<?php

$conn = mysql_connect("localhost", "root", "");
$db = mysql_select_db("myerp");

$sql = mysql_query("select ID,NOME,TIPO from fornecedor limit 5");

$outp = "";

if(mysql_num_rows($sql)>0){
    $outp .= "[";
    while($rs = mysql_fetch_array($sql)){
        $outp .= "{'id':'".$rs["ID"]."',";
        $outp .= "'nome':'".$rs["NOME"]."',";
        $outp .= "'tipo':'".$rs["TIPO"]."'}";
    }
    $outp .= "]";
}

echo json_encode($outp);

?>

Thank you in advance.

    
asked by anonymous 29.09.2017 / 00:46

1 answer

0

Look, without wanting to find out something ... I put a border="1" in the table, and I verified that the table is being mounted with the cells, but without the data. Empty cells.

Dai moved to other tables in the bank and even hit one that showed an ID field, and another that showed the name of the products. But it just shows tbm with track by $ index, otherwise it says it has repeated data.

Now: Is it a problem in BD Mysql? Any light?

    
30.09.2017 / 18:20