Jump to content

Enter scores - Seed after 2 games


tstats

Recommended Posts

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 score2
Reds 4 Pirates 3
Pirates 5 Astros 7
Astros 12 Mets 4
Mets 11 Reds 15

To get this data:

Team W L T RA RS Run Diff
Astros 2 0 0 9 19 10
Reds 2 0 0 14 19 5
Pirates 0 2 0 11 8 -3
Mets 0 2 0 27 15 -12

I am having to create the following EIGHT entries into my database:

team1 score1 team2 score2
Reds 4 Pirates 3
Pirates 3 Reds 4

Pirates 5 Astros 7
Astros 7 Pirates 5

Astros 12 Mets 4
Mets 4 Astros 12

Mets 11 Reds 15
Reds 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 do


My 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 10
sat10u.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 here

mysql_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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.