Javascript 如何在Angularjs php和mysql中通过ID获取数据
我已经设置了一个基本的angularjs应用程序。我可以使用$http服务连接数据库并获取数据。但是,我无法找到按ID显示单个项目的方法。请在单击时帮助我按ID显示单个数据 多谢各位 MySQL连接:Javascript 如何在Angularjs php和mysql中通过ID获取数据,javascript,php,mysql,angularjs,Javascript,Php,Mysql,Angularjs,我已经设置了一个基本的angularjs应用程序。我可以使用$http服务连接数据库并获取数据。但是,我无法找到按ID显示单个项目的方法。请在单击时帮助我按ID显示单个数据 多谢各位 MySQL连接: $sql = "SELECT * FROM categories"; $qry = $conn->query($sql); $data = array(); if($qry->num_rows > 0){ while($row = $qry->fetch_objec
$sql = "SELECT * FROM categories";
$qry = $conn->query($sql);
$data = array();
if($qry->num_rows > 0){
while($row = $qry->fetch_object()){
$data[] = $row;
}
} else {
$data[] = null;
}
$conn->close();
echo json_encode($data);
HTML NG-REPEAT
<section class="container-fluid is-grey" ng-controller="categoryController" style="border-bottom: 0;">
<div class="row">
<ul class="list-inline">
<li ng-repeat="cat in categories" class="col-md-3" style="padding-left:0; padding-right:0;">
<a href="#">
<div class="item-thumbnail">
<img ng-src="images/categories_images/{{ cat.cat_image }}" class="img-responsive">
</div>
<div class="item-details">
<h4>{{ cat.cat_name }}</h4>
</div>
</a>
</li>
</ul>
</div>
</section>
请详细说明一下,我想不出一种通过ID显示单个项目的方法?在PHP中,我们在URL like中传递一个变量,在另一个页面中,我们使用$\u GET variable检索分配给URL href变量的数据。我想了解如何在AngularJS中实现同样的目标。我已经创建了details.js页面,我想在其中显示单个产品的详细信息。您是否使用类别记录检索
Id
属性?我可以在主页上检索Id和数据,但我想在详细信息页面中显示产品的详细信息。我已经添加了标签,现在我想根据产品ID显示产品详细信息
var dsApp = angular.module('dsApp', []);
dsApp.controller('homeController', ['$scope', function($scope){
$scope.title = 'Digital Solutions Technologies';
}]);
dsApp.controller('categoryController', ['$scope', '$http', function($scope, $http){
$http.get("_admin/db.php")
.then(function(response) {
$scope.categories = response.data;
});
}]);