tags:

views:

61

answers:

1

There are a few parts to this code. The first part is creating fixtures.

$totalRounds = $teams - 1;
    $matchesPerRound = $teams / 2;
    $rounds = array();
    $roundDates = array();
    $curTime = time();

    for ($i = 0; $i < $totalRounds; $i++) {
        $rounds[$i] = array();
        $numDays = $i * 4;
        $roundDates[$i] = strtotime("+".$numDays." days",$curTime);

    }

    foreach($roundDates as $time) {
        for ($round = 0; $round < $totalRounds; $round++) {
            for ($match = 0; $match < $matchesPerRound; $match++) {
                $home = ($round + $match) % ($teams - 1);
                $away = ($teams - 1 - $match + $round) % ($teams - 1);
                // Last team stays in the same place while the others
                // rotate around it.
                if ($match == 0) {
                    $away = $teams - 1;
                }

                $rounds[$round][$match] = "$user[$home]~$team[$home]@$user[$away]~$team[$away]~$time";
            }
        }
    }

In the above code, a time is made for each round of fixtures. At the end of the code I have added $time.

        for ($i = 0; $i < count($rounds); $i++)
    {
        foreach ($rounds[$i] as $r)
        {
            $seperateUsers = explode("@",$r);
            $homeinfo = $seperateUsers[0];
            $awayinfo = $seperateUsers[1];
            $homedetails = explode("~",$homeinfo);
            $awaydetails = explode("~",$awayinfo);
            $database->addFixtures($homedetails[0], $homedetails[1], $awaydetails[0], $awaydetails[1], $awaydetails[2]);
        }   
    }

This piece of code uses breaks down the code from above to put into the table. For some reason, the date that is being entered into the database comes out 0000-00-00 00:00:00.

Is there anything anyone can see to fix this?

Edit: the loop isnt working? Am i missing anything on the actual loop?

+1  A: 

Sounds like $homedetails[0], etc. are not set. You could use a debugger to examine these values before calling addFixtures() or examine them by adding simple echo or var_dump() statements right before the call.

Fletcher Moore
Everything is hitting the database except $awaydetails[2].That field in the database is set as datetime.I assume that might not be what is needed?What format will my date in the code above go into the database in?
Luke
In this format `0000-00-00 00:00:00`. That is `YYYY-MM-DD HH:mm:ss`. strtotime() is resulting in a number of seconds since the "unix epoch". Use PHP's `date()` function to put it into the form above. I believe, `date("Y-m-d H:i:s",$time)` should work.
Fletcher Moore