2013-05-06 41 views
0

我正在製作一個顯示不同遊戲的支架。我想做一個查詢,然後根據哪一輪將數組拆分成新的數組。每一輪拆分查詢數組

IM目前得到的所有結果是這樣的:

$result = $mysqli->query("SELECT t1.name as team1, t2.name as team2, s.round, s.score_team_1, s.score_team_2 FROM scores s 
        LEFT JOIN teams t1 on s.team_id_1 = t1.team_id 
        LEFT JOIN teams t2 on s.team_id_2 = t2.team_id 
        WHERE s.cup_id = '1' 
        ORDER BY s.round ,s.game DESC")or die(mysql_error()); 


if($result->num_rows > 0) 
{ 
$rounds = array('1','2','3','4','5'); //no $ symbol 
while($rs = $result->fetch_assoc()) 
{ 
print_r($rs); 
} 
} 

我想這個數組分成分隔的人,因此所有符合第1輪,該行獲得投入爲圓一個陣列和那些圓2在第2輪陣列中依此類推。有誰知道我該怎麼做?

回答

0

你可以做到這一點像:

while($rs = $result->fetch_assoc()) 
{ 
    $rounds[$rs['s.round']] = $rs; 
} 

它將存儲在陣列分離的結果,例如獲得第1輪的結果,你必須做的:

$resultsForRound1 = $rounds[1];