Im trying to display percentages of games won and drawn between two selected teams, but im finding it hard to distinguish between either team.
Connection con = DBConnector.connect();
ResultSet rs = con.createStatement().executeQuery("SELECT DISTINCT t1.title AS title1, t2.title AS title2, g.score1, g.score2, g.winner AS winner, g.team1_id AS team1, g.home AS home FROM games g INNER JOIN teams AS t1 ON g.team1_id = t1.id INNER JOIN teams AS t2 ON g.team2_id = t2.id WHERE (t1.title = '"+team1 +"' AND t2.title = '" +team2+ "') OR (t1.title = '"+team2 +"' AND t2.title = '" +team1+ "');");
while(rs.next()){
if(rs.getString("team1").equals(rs.getString("home"))){
if(rs.getInt("winner") == 1){
teamOneWin++;
}else{
teamTwoWin++;
}
}else if(rs.getInt("winner") == 2){
if(rs.getString("team1").equals(rs.getString("home"))){
teamOneWin++;
}else{
teamTwoWin++;
}
}else if(rs.getInt("winner") == 0){
if(rs.getString("team1").equals(rs.getString("home"))){
draw++;
}
}
I am checking if the team1 value from the query, equals the home team value in the query. If they equal and team 1 is the value in column winner, i want teamOneWin to increment. I specify winner 1, winner 2 and winner 0 (match is a draw). I specify these because i have a winner 3 value which is not played also.
The line below i know is flawed, as team1 always equals home team, but i need a way to differentiate either team and increment the correct one upon winner value.
if(rs.getString("team1").equals(rs.getString("home"))){
Many thanks.
Aucun commentaire:
Enregistrer un commentaire