weixin_33735077 2013-06-10 20:53 采纳率: 0%
浏览 51

用PHP的Ajax汇率制度

                <div class="grid--cell fl1 lh-lg">
                    <div class="grid--cell fl1 lh-lg">
                        It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and   cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened,   <a href="/help/reopen-questions">visit the help center</a>.

                    </div>
                </div>
            </div>
            <div class="grid--cell mb0 mt8">Closed <span title="2013-06-11 10:15:27Z" class="relativetime">6 years ago</span>.</div>
        </div>
    </aside>

So, I grabbed this code from here. and I changed it a little to fit my db and display the rate based on my idGames, it's working fine, but now I want to do something like this.

How can I display the rates when I enter in the game page and rate that particular game? I have an index.php page, on which I show all my games, and I have a gameview.php that is the path for each game in index.php, so when you click in the game in index that game is displayed in gameview. Is there a way to implement that code to rate the games in gameview.php? I don't know if I'm being clear enough, but take that link as an example, it's exactly what I want. And I know that MYSQL is deprecated, but I don't know MYSQLi or PDO. So if you can help me with this I appreciate.

<?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>
</div>
  • 写回答

1条回答 默认 最新

  • 七度&光 2013-06-10 21:30
    关注

    Try this to retrieve the ratings count with starts. It will display based on your css style.

    If you user stars with css background u can this line like this

    $ratings = (@round($rs[total_value] / $rs[total_votes],1)) * 20;

    I hove it will helpfull.

    // Query to retrieve rating per game or article

    $query = "SELECT idGames FROM jogos";

    $result = mysql_query($query);

    while ($row = mysql_fetch_assoc($result)) {

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

    }

    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料