所以我正在製作高分系統,用於我的統一遊戲,使用mysql,php。爲什麼這個php查詢不起作用?
爲了獲取存儲在DB的高分信息,我寫的一樣,(DB有「分數」,「名稱」一欄中,而不是「排名」列名)
$sql = "SELECT id, score, name, CASE\n"
. " WHEN @prev_value = score THEN @rank_count\n"
. " WHEN @prev_value := score THEN @rank_count := @rank_count + 1\n"
. "END AS rank\n"
. "FROM BBR\n"
. "ORDER BY score DESC LIMIT $min, $max";
$result = mysql_query($sql) or Die('Query failed: ' . mysql_error());
$info = "";
while($found = mysql_fetch_array($result)){
$info = $info .'@'. $found['name'] .':'. $found['score'] .':'. $found['rank'];
}
echo $info;
,團結,我收到此信息並分割到每個字符串。
string[] score = serverHighScores[x].Split(':');
但在比分[0](名)本工作,得分[1](評分)好,但在比分[2](秩)不工作。
爲什麼?我應該如何解決? 謝謝。
該查詢
SET @prev_value = NULL;
SET @rank_count = 0;
SELECT id, score, name, CASE
WHEN @prev_value = score THEN @rank_count
WHEN @prev_value := score THEN @rank_count := @rank_count + 1
END AS rank
FROM BBR
ORDER BY score DESC
,這工作得很好在phpMyAdmin SQL。
在查詢中是否需要'\ n'? –
@IswantoSan它只是PHP的字符串連接。與mysql無關。 – leegod
嘗試打印'serverHighScores [x]'content –