2013-11-01 55 views
0

我正在制定一个计划生成器,其中每个团队都与其他团队进行比赛。我的数据库中的表,我需要像下面的输出, enter image description here匹配计划生成器算法

我至今尝试过是

<% 
    ResultSet rsteams = clmmodel_database.selectQuery("select count(ct.teamid) as teamcount, teamid,teamname from clm_team ct"); 
    while(rsteams.next()){ 
     int teamcount = rsteams.getInt("teamcount"); 
     int n = teamcount - 1; 
     int numofmatches = n*(n+1)/2; 
    %> 
    <h1>Team Count = <%out.print(teamcount);%></h1> 
    <h1>Number of Matches = <%out.print(numofmatches);%></h1> 
    <table> 
    <%for(int i =0;i<n;i++){%> 
    <tr> 
     //Here I need to display the matches row by row 
    </tr> 
    <%}%> 
    </table> 

    <%}%> 

以检索团队数和匹配的数量进行播放。请帮助我。

回答

1

这里是一个可能的解决方案:

<%for(int i =0; i< n - 1; i++){%> 
    <%for(int j = i + 1; i<n; j++){%> 
    <tr> 
     //Here you can display team i and team j 
    </tr> 
    <%}%> 
<%}%> 

我也建议你看看these算法。

+0

如何从两行中同时检索两个值?因为两个组的ID和名称都在两行 –

+0

您可以使用ResultSet.absolut方法(索引从1开始)http://docs.oracle.com/javase/6/docs/api/java/sql/ResultSet。 HTML#绝对(INT) –