基于php的Ajax速率系统
所以,我从我的电脑上获取了这个代码。我对它做了一些修改,以适应我的db,并根据我的idGames显示速率,它工作正常,但现在我想做一些类似的事情 当我进入游戏页面并对特定游戏进行评分时,如何显示评分? 我有一个基于php的Ajax速率系统,php,jquery,ajax,rating-system,Php,Jquery,Ajax,Rating System,所以,我从我的电脑上获取了这个代码。我对它做了一些修改,以适应我的db,并根据我的idGames显示速率,它工作正常,但现在我想做一些类似的事情 当我进入游戏页面并对特定游戏进行评分时,如何显示评分? 我有一个index.php页面,上面显示了我所有的游戏,还有一个gameview.php,它是index.php中每个游戏的路径,因此当你点击游戏索引时,游戏会显示在gameview中。在gameview.php中,有没有一种方法可以实现该代码来对游戏进行评分?我不知道我是否足够清楚,但以这个链接
index.php
页面,上面显示了我所有的游戏,还有一个gameview.php
,它是index.php
中每个游戏的路径,因此当你点击游戏索引时,游戏会显示在gameview中。在gameview.php
中,有没有一种方法可以实现该代码来对游戏进行评分?我不知道我是否足够清楚,但以这个链接为例,这正是我想要的。我知道MYSQL
不受欢迎,但我不知道MYSQLi
或PDO
。如果你能帮我,我很感激
<?php
include_once('settings.php');
connect();
$query = "SELECT idGames FROM jogos";
$result = mysql_query($query);
$ids = array();
while ($row = mysql_fetch_assoc($result)) {
$ids[] = $row['idGames'];
}
?>
<html>
<head>
</head>
<body>
<?php
for ($i = 0; $i < count($ids); $i++) {
$rating_tableName = 'jogos';
$id = $ids[$i];
$q = "SELECT total_votes, total_value FROM $rating_tableName WHERE idGames=$id";
$r = mysql_query($q);
if (!$r)
echo mysql_error();
while ($row = mysql_fetch_array($r)) {
$v = $row['total_votes'];
$tv = $row['total_value'];
if ($v)
$rat = $tv / $v;
else
$rat = 0;
}
$j = $ids[$i];
$id = $ids[$i];
echo '<div class="product">
Rate Item ' . $j . '
<div id="rating_' . $id . '" class="ratings">';
for ($k = 1; $k < 6; $k++) {
if ($rat + 1 > $k)
$class = "star_" . $k . " ratings_stars ratings_vote";
else
$class = "star_" . $k . " ratings_stars ratings_blank";
echo '<div class="' . $class . '"></div>';
}
echo ' <div class="total_votes"><p class="voted"> Rating: <strong>' . @number_format($rat) . '</strong>/5 (' . $v . ' vote(s) cast)
</div>
</div></div>';
}
?>
</body>
</html>
尝试此操作以检索开始时的评级计数。它将根据您的css样式显示 如果你使用css背景的星星,你可以这样写这行 $ratings=(@round($rs[总票数]/$rs[总票数],1))*20 我相信这会有帮助的 //查询以检索每个游戏或文章的评级 $query=“从jogos中选择idGames” $result=mysql\u query($query) while($row=mysql\u fetch\u assoc($result)){
$id=$row['idGames'];
$sql=“从$rating\u tableName(其中idGames=$id)中选择总票数、总票数”;
$results=mysql\u查询($sql);
$rs=mysql\u fetch\u数组($results);
//星的集合clss
$ratings=(@round($rs[总票数]/$rs[总票数],1));
$class=“star”..$ratings。“ratings\u stars ratings\u blank”//带有css样式的星星
评级:$ratings/5//显示五分之一
}我不确定你想要达到什么目标。你是在寻找那些被部分填满的星星,而不是将评级四舍五入到最接近的满星吗?不,忘了星星吧,我正在尝试在我的gameview.php页面中显示评级系统,以便人们可以在游戏中投票。我只是想说谢谢你,我真的很感激,但是我遇到了很多解析错误,你能格式化它吗?因为我没有为此准备代码,我只是告诉你我希望你能修改它。如果你需要任何帮助,我会帮你让我知道,谢谢。
$id = $row['idGames'];
$sql = "SELECT total_votes, total_value FROM $rating_tableName WHERE idGames=$id";
$results = mysql_query($sql);
$rs = mysql_fetch_array($results);
// set clss of star
$ratings = (@round($rs[total_value] / $rs[total_votes],1));
<div class="product">
<div id="rating_' . $id . '" class="ratings">
$class = "star_" . $ratings . " ratings_stars ratings_blank";//stars with css style
<div class="' . $class . '"></div>
Rating: <strong> $ratings / 5 </strong> // shows count out of 5
</div>