2011-10-17 10 views
0

私がしようとしている、把握するためにいくつかのコードを残してきたために選手のスコアを取得する方法...現在の週

私は選手たちが現在の週のためのスコアを取得することで必要なもの
public function scoreboard($ttime, $numb = 10) {  

    if ($ttime == "day") { $timesearch = $this->myTime - 86400; } 

    if ($ttime == "week") { $timesearch = $this->myTime - 604800; } 

    if ($ttime == "month") { $timesearch = $this->myTime - 18144000; } 

    if ($ttime == "hiscore") { $timesearch = $this->myTime - 1000000000; } 

    //get top 10 ------------------ 

    return @mysql_query("SELECT uid, name, score, FROM table WHERE scoredate>$timesearch ORDER BY score DESC LIMIT $numb"); 

    } 

、つまり、スコアが(サーバーの日付に基づいて)作成された実際の週ですが、私はコードがそれをしないと思いますか?それは現在の日付を取るとちょうど7日間戻って行くようですか?

+1

を使用scoredate' 'のフィールドタイプは何ですか? int?日付時刻? –

答えて

1

あなたの週は月曜日に開始した場合、

<?php 

if (date('N') == '1') 
    $time = strtotime('today'); 
else 
    $time = strtotime('last monday'); 

$query = sprintf('SELECT uid, name, score, FROM table WHERE scoredate>"%s" ORDER BY score DESC LIMIT %d', date('Y-m-d', $time) . ' 00:00:00', $numb); 
関連する問題