使用angularJS显示来自phpmyadmin的数据

使用angularJS显示来自phpmyadmin的数据,php,angularjs,Php,Angularjs,我希望使用angularJS显示来自mysql数据库的数据,但这一切都是徒劳的。请检查我的代码并建议我哪里出了问题 <?php $host = "localhost"; $user = ""; $pass = ""; $database = "abc"; $con = mysql_connect($host,$user,$pass); if (!$con) { die('Could not connect: ' .

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

  <?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);
?>
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>

  • {{product.name}
当我运行
index.html
时,我得到了无限多的项目符号列表,没有显示结果


我哪里出错了?

我同意Alexander的观点,如果您可以从浏览器控制台获取JSON数据,这会有所帮助

我认为您希望在php代码中执行类似的操作,以便只获得名称和描述
$arr[]=array('name'=>$name,'description'=>$description)而不是
$arr[]=$row

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

希望这有帮助


--dan

能否显示发送到页面的JSON数据?也许PHP没有输出您期望的结果。我的错误:)我忘了在生成的jsonI use Services_JSON中添加[]和逗号,这对我来说是完美的,遵循了您的教程z22,我也遇到了同样的情况,很多项目符号,忘记在JSON中添加[]和逗号是什么意思?你把它放哪儿了(
    <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>