2017-08-17 138 views
1

我想每周选择一组游戏比赛。我怎么能做到这一点。 它假设从当前时间+7天和-7天显示来自之前和新游戏的数据。从当前日期到提前7天和过去7天询问数据

目前,我有这个

function testFR(){ 
    $DateFrom = new DateTime(); 
    $DateTo = new DateTime(); 
    $DateTo->add(new DateInterval("P7D")); 
    $laMatches = (array)WaterpoloAPICached::call("Matches", "getMatches", Array(
     isset($_GET["SeasonId"]) ? $_GET["SeasonId"] : "", 
     isset($_GET["DepartmentId"]) ? $_GET["DepartmentId"] : "", 
     isset($_GET["ClubId"]) ? $_GET["ClubId"] : "", 
     isset($_GET["TeamId"]) ? $_GET["TeamId"] : "", 
     isset($_GET["PoolId"]) ? $_GET["PoolId"] : "", 
     date_format($DateFrom, 'd-m-Y'), 
     date_format($DateTo, 'd-m-Y'), 
     isset($_GET["RefereeId"]) ? $_GET["RefereeId"] : "",  
    )); 
    // Sort Matches ascending 
     usort($laMatches, function($a, $b) { 
         return stringToUnix($a->Date) - stringToUnix($b->Date); 
     }); 
/* echo "<h6 id='rcorners' style='background-color:#3db7e4; padding: 1rem; color:white;'><strong>Wedstrijden</strong></h6>"; */ 
    echo "<table class='hover'>"; 
    echo "<tbody >";   
    $lnToday = date("d-m-Y", strtotime("+7 days"));      
          $lcCurrent = "";       
     foreach($laMatches as $loMatch) { 
      if(stringToUnix($loMatch->Date) >= $lnToday) { 
       if($lcCurrent != $loMatch->Date) {  
      echo "<thead>"; 
      echo "<tr >"; 
      echo "<th class='text-center'>"; 
      echo "$loMatch->Date</th>"; 
      echo "<th class='text-center'></th>";  
      echo "<th class='text-center'></th>"; 
      echo "<th class='text-center'></th>"; 
      echo "<th class='text-center'>Division</th>"; 
      echo "</tr>";     
      echo "</tr> 
       </thead>";   
        }    
        $lcCurrent = $loMatch->Date;      
      echo "<tr class='text-center'>"; 
       echo "<td >$loMatch->Time</td>"; 
       echo "<td>$loMatch->HomeTeam </td>"; 
       echo "<td><strong><a href='..\match?MatchId=".$loMatch->Id."&Report=".$loMatch->MatchReport."'>$loMatch->ResultHome - $loMatch->ResultGuest </a></strong></td>"; 
       echo "<td> $loMatch->AwayTeam</td>"; 
       echo "<td> $loMatch->DepartmentName</td>"; 
      echo "</tr>"; 
      } 
     }  
     echo "</tbody>"; 
     echo "</table>";   
} 

问题已经解决了!对于那些有类似问题的人...希望这可以帮到你!

+0

正如您所看到的标记已被编辑。这里没有jQuery,除非你想把逻辑移动到客户端 – mplungjan

+0

th Rory!编辑 –

回答

0

你差不多了。您可以像这样通过程序化方式添加/减去日期时间段:

$lnToday = date("d-m-Y", strtotime("+7 days")); 
+0

thx米兰我会尝试的! –

+0

仍然获得所有游戏的列表。我究竟做错了什么?我编辑了迄今为止我所拥有的内容。 ..我仍然需要一个有点开始时间结束时间? –

+0

很抱歉听到这些。 '$ loMatch-> Date'返回什么? – ishegg