2011-04-16 45 views
0

我有一張足球比賽的桌子,我需要根據日期返回最後和下一場比賽。有沒有簡單的方法來做到這一點?該表有日期,時間,團隊,所以需要按團隊進行分組。這就是我目前做的下一個裝置。之前和未來的比賽mysql

任何幫助將感激地讚賞:)

+0

它是什麼,你現在又做了嗎? – 2011-04-16 11:35:10

回答

0

你有一個腳本語言如PHP要做到這一點,至少我會做到這一點。我不是一名專業的開發人員,但是我使用php腳本快速寫出了以前匹配出的mysql數據庫。你可以爲下一場比賽做出類似的事情。可能有一個更簡單的方法來做到這一點,但這個腳本的作品...

<?php 

/*get the current day*/ 
$day = date("d"); 

$previous = array(); 
$j = 0; /*this variable will say on which index we have to store the team name in the array previous*/ 
$k = 1; /*this variable will say how much days we have to count back*/ 

/*now we get the previous math out of the database be counting down the days and looking if there is a record*/ 
for($i=$day; $i>0; $i--) { 
    $date = date("dmY", strtotime("-$k days")); 

    $result = mysql_query("SELECT * FROM `football` WHERE `date`='$date'") or die (mysql_error()); 
    $num = mysql_num_rows($result); 
    $fetch = mysql_fetch_array($result); 

    if($num == 1) { 
     $previous[$j] = $fetch["team"]; 
     $j++; 
    } 
    $k++; 
} 

echo $previous[0]; 

?>