如何添加我自己的评分系统? [英] How can I add my own rating system?
问题描述
如何添加评分系统?我的博客从数据库中获取帖子.
如果不存在则创建表`posts`(`id` int(11) NOT NULL AUTO_INCREMENT,`video` varchar(255) 非空,`title` 长文本非空,`text` 长文本非空,`posted_by` 长文本非空,主键(`id`)) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1 ROW_FORMAT=COMPACT;
在 index.php 中,我使用 echo 调用它们,一切正常.
示例:
<div class="row"><div class="col-md-8"><h1 style="颜色:白色;"class="my-4">我的博客<div class="card mb-4"><div class="embed-responsive embed-responsive-16by9"><iframe style="border:0;"class="embed-responsive-item" width="450" height="240" src=""allowfullscreen></iframe><div class="card-body"><h2 class="card-title">Title</h2><p>文本</p>
<div class="card-footer text-muted">页脚</div>
For Rating System 创建表例如post_rating 将列作为id 为 int(自动增量),post_id 为 int,user_id 为 int(如果适用于您的项目)评级为 int
然后当用户想要给 posts_rating 表提供评分时插入值.
要显示帖子的当前评分,请执行 sql 语句:
选择 round(AVG(rating),1) 作为 currentRating FROM post_rating WHERE post_id=".$post_id;
How can I add a rating system? My blog gets its posts from database.
CREATE TABLE IF NOT EXISTS `posts` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`video` varchar(255) NOT NULL,
`title` longtext NOT NULL,
`text` longtext NOT NULL,
`posted_by` longtext NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1 ROW_FORMAT=COMPACT;
In index.php I call them using echo, everything works fine.
Example:
<div class="container">
<div class="row">
<div class="col-md-8">
<h1 style="color:white;" class="my-4"> My Blog
</h1>
<div class="card mb-4">
<div class="embed-responsive embed-responsive-16by9">
<iframe style="border:0;" class="embed-responsive-item" width="450" height="240" src="" allowfullscreen></iframe>
</div>
<div class="card-body">
<h2 class="card-title">Title</h2>
<p>Text</p>
</div>
<div class="card-footer text-muted">Footer</div>
</div>
For Rating System create a table e.g. posts_rating having columns as id as int(auto incrememt), post_id as int, user_id as int(if applicable in your project) rating as int
Then when a user wants to give rating insert value to the posts_rating table.
To display current rating for the post execute the sql statement:
select round(AVG(rating),1) as currentRating FROM post_rating WHERE post_id=".$post_id;
这篇关于如何添加我自己的评分系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!