我一直在尝试从本地服务器从MySql获取数据。我的本地服务器是WAMP。
这是我的index.php
<html lang="en-US">
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<body ng-app='myApp'>
<div ng-controller="customersCtrl">
<table>
<thead><tr><th>ID</th><th>Name</th><th>Email</th></tr></thead>
<tbody>
<tr ng-repeat="user in names">
<td>{{user.id}}</td>
<td>{{user.name }}</td>
<td>{{user.city}}</td>
</tr>
</tbody>
</table>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
$http.get("customers_mysql.php")
.success(function (response) {$scope.names = response.records;});
});
</script>
</body>
</html>
这是我的customers_mysql.php
$conn = new mysqli("localhost", "root", "", "test");
$sql = "SELECT name, city, country FROM customers";
$results = mysqli_query($conn, $sql);
$data = array();
while($row = mysqli_fetch_assoc($results)) {
$data[] = $row;
}
$json = json_encode( $result );
echo $json;
当我加载index.html页面时,我根本得不到任何结果。 所以我认为我的sql有点不对劲所以我创建了一个新的php页面
名为textCustomers.php
<?php
include('customers_mysql.php');
$results = mysqli_query($conn, $sql);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} else {
if (mysqli_num_rows($results) > 0) {
while($row = mysqli_fetch_assoc($results)) {
echo '<tr>';
echo '<td>' . $row['name'] . '</td>';
echo '</tr>';
}
}
}
?>
这很有效。
无论如何,我一直在跟踪stackoverflow,w3和其他网站的代码,但它们都没有工作。我做错了什么?
谢谢
答案 0 :(得分:0)
尝试这样的事情:
HTML5 <video> tag