tstats Posted April 30, 2006 Share Posted April 30, 2006 I currently am using one table to display a tournament: id int(11) age int(11) game int(11) day varchar(25) time varchar(10) field varchar(50) team1 varchar(50) score1 int(11) score2 int(11) team2 varchar(50) diff int(11) seed int(11) pool int(11) group varchar(4)Let's say I have a 4 team tournament, and the scores are this:team1 score1 team2 score2Reds 4 Pirates 3Pirates 5 Astros 7Astros 12 Mets 4Mets 11 Reds 15To get this data:Team W L T RA RS Run DiffAstros 2 0 0 9 19 10Reds 2 0 0 14 19 5Pirates 0 2 0 11 8 -3Mets 0 2 0 27 15 -12I am having to create the following EIGHT entries into my database:team1 score1 team2 score2Reds 4 Pirates 3Pirates 3 Reds 4Pirates 5 Astros 7Astros 7 Pirates 5Astros 12 Mets 4Mets 4 Astros 12 Mets 11 Reds 15Reds 15 Mets 11 And then doing the following PHP code to get them to sort and display:[code]$sql = 'SELECT id,team1, Sum(If(score1>score2,1,0)) AS Wins, Sum(If(score1<score2,1,0)) AS Losses, Sum(If(score1=score2,1,0)) AS Ties,Sum(score2) AS Allowed, Sum(score1) AS Scored, Sum(diff) AS Differential' . ' FROM tour' . ' WHERE age=10 AND day<>"Sun" AND (score1<>0 OR score2<>0)' . ' GROUP BY team1' . ' ORDER BY Wins DESC, Losses ASC, Allowed ASC, Scored DESC LIMIT 0, 30 '; [/code]I have thought about 2 different ways to change this: 1) When I update a score, add another record with the teams inverted and the scores inverted 2) Do a lot of work and create a "normalized" database - which I believe I need to doMy current update code is below - I am updating each record with an update button - I have searched for the code to do a list box for each game and each age, and then update that record - cannot find it -Update form for age 10sat10u.php[code]<?php*/ connect to table here$result=mysql_query("SELECT * FROM tour WHERE age=10 AND day<>'Sun' ORDER BY game");$num=mysql_num_rows($result);$i=0;while ($i < $num) {$id=mysql_result($result,$i,"id");$game=mysql_result($result,$i,"game");$team1=mysql_result($result,$i,"team1");$score1=mysql_result($result,$i,"score1");$team2=mysql_result($result,$i,"team2");$score2=mysql_result($result,$i,"score2");?><table width="350" cellpadding="3" cellspacing="0" border="2"><tr align="center" valign="top"><td align="center" colspan="1" rowspan="1" bgcolor="ORANGE"><form action="sat10u2.php" method="post"><FONT SIZE="1"><B>ID:<input type="text" name="ud_id" value="<? echo "$id"?>" size="1"></B><B>Game: <input type="text" name="ud_game" value="<? echo "$game"?>" size="1"></B><B>Team1: <input type="text" name="ud_team1" value="<? echo "$team1"?>" size="10"></B><BR><B>Score1: <input type="int" name="ud_score1" value="<? echo "$score1"?>" size="1"></B><B>Score2: <input type="int" name="ud_score2" value="<? echo "$score2"?>" size="1"></B><B>Team2: <input type="text" name="ud_team2" value="<? echo "$team2"?>" size="10"></B><input type="Submit" value="Update"></form></FONT></td></tr></table><?++$i;}?>[/code]sat10u2.php[code]<html><head><title></title></head><body><?$ud_id=$_POST['ud_id'];$ud_team1=$_POST['ud_team1'];$ud_team2=$_POST['ud_team2'];$ud_score1=$_POST['ud_score1'];$ud_score2=$_POST['ud_score2'];$ud_seed=$_POST['ud_seed'];*/connect to table code heremysql_query(" UPDATE tour SET team1='$ud_team1' ,team2='$ud_team2',score1='$ud_score1',score2='$ud_score2' WHERE id='$ud_id'");mysql_close($link);require 'sat10u.php';?></body></html> [/code]I am sure some of you willing smart people could help me get in the right direction -Thanks! Link to comment https://forums.phpfreaks.com/topic/8768-enter-scores-seed-after-2-games/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.