点击发布链接可在另一页上显示完整结果 [英] Click post link to display full results on another page
问题描述
我想单击数据库中ID为ID的链接(在posts.html页上),然后使用AngularJS,MySQLi和PHP在display.html中查看该帖子链接的完整内容.请参见下图:
I want to click on a link with id from database (on posts.html page) then view the full content of that post link in a display.html using AngularJS, MySQLi, and PHP. Please see the image below:
这是我到目前为止设法做到的:Posts.html
here is what I have managed to do so far: Posts.html
<table class="table table-bordered" ng-controller="postController"
ng-init="show_data()">
<tr>
<th>Description</th>
</tr>
<tr ng-repeat="x in news">
<td><a href="">{{x.description}}</a></td>
</tr>
</table>
这是我的发布控制器:postController.js
Here is my post controller: postController.js
"USE STRICT";
app.controller('postController', function ($scope, $http) {
$scope.show_data = function () {
$http.get("display.php")
.success(function (data) {
$scope.news = data;
});
}
});
这是我的display.php代码:
And here is my display.php code:
<?php
require_once "config.php";
$output = array();
$query = "SELECT * FROM news";
$result = mysqli_query($conn, $query);
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_array($result)) {
$output[] = $row;
}
echo json_encode($output);
}
?>
我的display.html是:
My display.html is:
<div >
<div>{{id}}</div>
<div>{{title}}</div>
<div>{{article}}</div>
<div>{{tag}}</div>
<div>{{author}}</div>
</div>
如何在display.html上显示从特定链接的数据库获取的结果?
How to display the results fetched from the database of the particular link on display.html?
推荐答案
这应该可以完成:
在您的配置中:
app
.config(function ($routeProvider ...) {
$routeProvider
...
.when('/posts', {templateUrl: 'posts.html', controller: function($scope, $http) {
$scope.getPosts = function() {
$http.get('posts.php').then(function (response) {
$scope.posts = response.data;
});
};
}})
.when('/display/:id', {templateUrl: 'display.html', controller: function($scope, $routeParams, $http) {
$http.get('display.php', {id: $routeParams.id}).then(function (response) {
$scope.post = response.data;
});
}})
})
在 posts.html
中:
<table class="table table-bordered" ng-controller="postController" ng-init="getPosts()">
<tr>
<th>Description</th>
</tr>
<tr ng-repeat="post in posts">
<td><a ng-href="display/{{post.id}}">{{post.description}}</a></td>
</tr>
</table>
在 display.html
中:
<div ng-if="post">
...
<div>{{post.title}}</div>
...
</div>
在 display.php
中:
$id = $_GET['id'];
// then retrieve post by this id and return as json item
这篇关于点击发布链接可在另一页上显示完整结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!