我的iphone游戏的高分系统 [英] High score system from my iphone game

查看:89
本文介绍了我的iphone游戏的高分系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在PHP中使用这个循环从MySQL表中选择我游戏中的所有分数。

I have this loop in PHP to select all my scores from my game from a MySQL table.

我的查询是:

$sql = "SELECT * FROM $table WHERE ";

    switch($type) {
        case "global":
            $sql .= "1 ";
            break;
        case "device":
            $sql .= "udid = '$udid' ";
            break;
        case "name":
            $sql .= "name = '$name' ";
            break;
    }

    $sql .= "ORDER BY $sort ";
    $sql .= "LIMIT $offset,$count ";

    $result = mysql_query($sql,$conn);

udid 是唯一标识符。循环:

The udid is a unique identifier. And the loop:

 while ($row = mysql_fetch_object($result)) {
                echo '<tr>
                        <td>
                        '.$rank.' 
                        </td>
                                                <td>
                        '.$row->name.'
                        </td>
                        <td>
                        '.$row->score.'
                        </td>
                                        <td>
                        '.$row->udid.'
                        </td>

                      </tr>';
                                 $rank++;
            }

我的问题很简单,所以一个人可以在游戏里面看到哪个等级他是。
如何从循环之外的 udid 中选择排名。

My question is simple, so a person can see inside the game at which rank he is. "How to select a rank from a udid, outside of the loop".

也许正在制作从 udid 中选择排名的新查询,或者在循环中设置变量?

Perhaps making a new query which selects the rank from a udid, or set up a variable from in the loop?

推荐答案

一个选项是编写一个函数,根据所有其他分数计算用户的排名并返回它。
然后,当用户想要查看他的排名时调用它。

One option is writing a function that calculate the user's rank based on all the other's scores and returning it. Then , calling it when the user wants to see his rank.

据我所知,MMORPG游戏(例如)有为每个
玩家在他们的数据库中排名
字段,他们使用每日或每小时的cron-job来更新该等级。
因此,每次玩家
只想看到他的等级时,你不需要运行'计算 - 排名'功能,而只需要获取该字段的值。

As far as I know , MMORPG games (for instance) have a rank field in their DB for each player and they use a daily or hourly cron-job to update that rank. So instead of running the 'calculate-the-rank' function each and every time a player just want to see his rank, you'll just need to fetch the value of the field.

EDIT:该功能的代码(不要忘记将 rank 字段添加到您的数据库表)

code for the function (don't forget to add the rank field to your DB table)

文件:


cronjob_update_rank.php:

cronjob_update_rank.php:



require 'config.php'; //Or whatever contains your config and DB connection.

$rank = 1; //The best player ranked as 1
$getMembers = mysql_query("SELECT id FROM members ORDER BY `score` DESC");
while($mem = mysql_fetch_array($getMembers))
{
 mysql_query("UPDATE members SET rank='$rank' WHERE id='{$mem['id']}'");
 $rank++;
}

请注意,这只是一个示例代码,您需要自定义它满足您的需求。

Please notice , it's just a sample code , you'll need to customize it for your needs.

使用服务器面板在该文件上创建每日cronjob。
(或询问您的托管服务提供商支持)。

Use your server panel to create a daily cronjob on that file. (or ask for your hosting provider support with it).

这篇关于我的iphone游戏的高分系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆