使用angularJS显示phpmyadmin中的数据


Display data from phpmyadmin using angularJS

我希望使用angularJS显示来自mysql database的数据,但都是徒劳的。请检查我的代码,并建议我哪里出了问题?

  <?php
    $host = "localhost"; 
    $user = ""; 
    $pass = ""; 
    $database = "abc";
    $con = mysql_connect($host,$user,$pass);
    if (!$con) {
        die('Could not connect: ' . mysql_error());
    }
    echo 'Connected successfully'; 
    mysql_select_db($database,$con);  
     //select
    $query = "SELECT * FROM `product`"; 
    $result = mysql_query($query) OR die(mysql_error()); 
    $arr = array();
    //now we turn the results into an array and loop through them. 
    while ($row = mysql_fetch_array($result)) { 
        $name = $row['name']; 
        $description = $row['description']; 
        //echo 'This is: ' . $name . ' ' . $description . "<br/>'n"
        $arr[] = $row;
    } 
    echo json_encode($arr);
?>

控制器.js

 function ProductListCtrl($scope,$http) {
    $http.get('php/connect.php').success(function(data) {
        $scope.products = data;
    });
    //$scope.orderProp = 'name';
}

index.html

    <html ng-app>
    <head>
        <script src="../angular-1.0.1.min.js"></script>
        <script src="js/controllers.js"></script>
    </head>
    <body>
    <ul ng:controller="ProductListCtrl">
        <li ng:repeat="product in products">
            {{product.name}}
        </li>
    </ul>
    </body>
</html>

当我运行index.html时,我得到了无限的项目符号列表,但没有显示结果。

我哪里错了?

我同意Alexander的观点,如果你能从浏览器控制台获得JSON数据,那会有所帮助。

我想你想在php代码中做这样的事情,只获取名称和描述$arr[] = array('name' => $name, 'description' => $description);代替$arr[] = $row;

您可能会从php代码中以html的形式返回一个错误,$http将其分解为数组。

希望这能帮助

--dan