我希望显示mysql database
使用的数据,angularJS
但都是徒劳的。请查看我的代码并建议我哪里出错了?
<?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';
}
索引.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
,我得到无限的子弹列表,没有显示结果。
我哪里错了?