サッカーの試合のテーブルがあり、日付に基づいて最後の試合と次の試合を返す必要があります。これを行う簡単な方法はありますか?テーブルには日付、時間、チームがあるため、チームごとにグループ化する必要があります。これは、次のフィクスチャを取得するために現在行っていることです。
どんな助けでも感謝します:)
php のようなスクリプト言語でこれを行う必要があります。少なくとも私はこれを行います。私はプロの開発者ではありませんが、mysql データベースから前の一致を取得する高速な php スクリプトを書きました。次の試合でも似たようなものを作ることができます。おそらくもっと簡単な方法がありますが、このスクリプトは機能します...
<?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];
?>