[英]How can I add my own rating system?
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. 在index.php中,我使用echo调用它们,一切正常。
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 eg 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 对于评级系统,创建一个表,例如,posts_rating,其列的id为int(自动incrememt),post_id为int,user_id为int(如果适用于您的项目),评价为int
Then when a user wants to give rating insert value to the posts_rating table. 然后,当用户希望给posts_rating表提供评分插入值时。
To display current rating for the post execute the sql statement: 要显示帖子的当前评分,请执行sql语句:
select round(AVG(rating),1) as currentRating FROM post_rating WHERE post_id=".$post_id; 选择round(AVG(rating),1)作为currentRating FROM post_rating WHERE post_id =“。$ post_id;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.