gpt4 book ai didi

php - 如何添加自己的评级系统?

转载 作者:行者123 更新时间:2023-11-29 17:26:06 24 4
gpt4 key购买 nike

如何添加评级系统?我的博客从数据库获取帖子。

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;

在index.php中我使用echo调用它们,一切正常。

示例:

    <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>

最佳答案

为评级系统创建一个表例如posts_ rating 的列为id为int(自动递增),post_id 作为 int,user_id as int(如果适用于您的项目)评级为 int

然后,当用户想要给 posts_ating 表评分时插入值。

要显示帖子的当前评分,请执行 sql 语句:

选择 round(AVG( rating),1) 作为 currentRating FROM post_ rating WHERE post_id=".$post_id;

关于php - 如何添加自己的评级系统?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50956908/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com