开发者

previous and next match mysql

I have a table of football fixtures, and I need to return the last and next match based on date. Is there a simple way to do this? the table has date, time, team, so would need to group it by team. This is what I currently do t开发者_开发百科o get the next fixture.

any help would be gratefully appreciated :)


You have to do this with a scripting language like php, at least I would do this. I am not a professional developer but I wrote fast following php script that gets the previous match out of a mysql database. You can make something similar for the next match. Probably there is a much easier way to do it but this script works...

<?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];

?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜