2010-08-05 42 views
0

我目前正在爲我的遊戲網站提供高分數系統。我已經爲此寫了代碼。它只顯示1-球員。我想要顯示整體頂級球員,當我點擊頂級球員的網址,並希望顯示每月排名前10的球員,當我點擊每月頂級球員url.How這樣做。我正在嘗試2天。我感到很震驚。請看看這個。代碼如下。 僅供參考請看這裏。我需要這樣。任何想法.. http://www.gamesheep.com/highscores.php?id=the-champions-3d-game&table=w使用php mysql排名前10的球員和每月排名前10的球員

<?php 
include_once("_data.php"); 

$game_name = "test"; 
$db_table = "newhs_" . $game_name; 

$conn = mysql_connect($db_host, $db_user, $db_pass); 
mysql_select_db($db_name, $conn); 

// Alltime records... 

if ($order=="name") { 
$sql1 = "SELECT id FROM $db_table ORDER BY name ASC"; 
} else { 
$sql1 = "SELECT id FROM $db_table ORDER BY score DESC"; 
} 
$result1 = mysql_query($sql1); 

// Top 10 players.... 

if($top10 == "name"){ 
$sql2 = "SELECT name,score FROM $db_table ORDER BY score DESC LIMIT 10"; 
} else { 
$sql2 = "SELECT id FROM $db_table ORDER BY score DESC"; 
} 
$result2 = mysql_query($sql2); 

// Monthly top 10 players..... 

if($mtop10 == "name"){ 
$sql3 = "SELECT name, score FROM $db_table WHERE date(dateinfo) = CURdate()"; 
} else{ 
$sql3 = "SELECT id FROM $db_table ORDER BY score DESC"; 
} 
$result3 = mysql_query($sql3); 


if (!$flash) { 
if ($order == "name") { 
    $HTM_1 = "<table cellpadding='0' cellspacing='0' border='0' width=" . $table_width . "> 
    <tbody> 

    <tr align=center><td>" . $table_prop . "<tr align=center> 
    <th bgcolor='" . $t_color . "'>" . $t_font . "Pos</font></th> 
    <th bgcolor='" . $t_color . "'>" . $t_font . "Name</a></font></th> 
    <th bgcolor='" . $t_color . "'>" . $t_font . "'>Score</font></th> 
    </tr>"; 
} else { 
    $HTM_1 = "<table cellpadding='0' cellspacing='0' border='0' width=" . $table_width . "> 
    <tbody> 
    <tr align=center><td>" . $table_prop . "<tr align=center> 
    <th bgcolor='" . $t_color . "'>" . $t_font . "Pos</font></th> 
    <th bgcolor='" . $t_color . "'>" . $t_font . "Name</a></font></th> 
    <th bgcolor='" . $t_color . "'>" . $t_font . "Score</font></th> 
    </tr>"; 
} 
echo "$HTM_1"; 
} 

$num = 1; 

while($r = mysql_fetch_object($result1)) 
{ 
$result = mysql_db_query($db_name, "SELECT name, score from $db_table WHERE id='{$r->id}'"); 
$resultArray = mysql_fetch_array($result); 
$id = $resultArray["id"]; 
$name = $resultArray["name"]; 
$score = $resultArray["score"]; 
if ($sec==1) { 
    if ($num <= $sec_size) { 
    $HTML = " 
    <tr bgcolor='" . $m_color . "' align='center'><td>" . $m_font . $num . "</td> 
    <td>" . $m_font . $name . "</font></td> 
    <td>" . $m_font . $score . "</font></td> 
    </tr>"; 
    echo "$HTML"; 
    } 
} else { 
    if ($num <= $st_size) { 
    //echo "&name$num=$name&score$num=$score"; 
    if ($flash == 1) { 
    echo "&name$num=$name&score$num=$score"; 
    } else { 
     echo "&name$num=$name&score$num=$score&num$num=$num&gamename=$game_name"; 
    $HTML = " 
    <tr bgcolor='" . $m_color . "' align='center'><td>" . $m_font . $num . "</td> 
    <td>" . $m_font . $name . "</font></td> 
    <td>" . $m_font . $score . "</font></td> 
    </tr>"; 
    echo "$HTML"; 
    } 
    $num++; 
    } 
} 
} 

mysql_close ($conn); 
?> 
+2

你需要SQL,PHP或兩者的幫助嗎? – RedFilter 2010-08-05 09:59:20

+0

你是否實現了這個目標,演示網址看起來不錯? – 2010-09-01 23:05:55

+0

是的,我需要這兩個幫助.. – phphunger 2010-09-06 07:28:44

回答

0

請考慮添加數據庫表內容的預覽。 也許表中只有一排?

從快速的樣子可以看出,問題可能出現在查詢中, 的條件,因爲畢竟查詢工作並從數據庫中提取內容。

其中date(dateinfo)= CURDATE()

順便說一下,添加 「LIMIT 10」 爲 「每月前10名的球員」 查詢。