Jump to content

shmeeg

Members
  • Posts

    15
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

shmeeg's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Yes I have a database connection. I'm not sure about the second part. I'm sure that's not what the error is though?
  2. Can't figure out why the page wont save after clicking save. $KOHDE="index.php?s=admin"; $LOMAKE_W = 400; $TEXTAREA_W = 50; $TEXTAREA_H = 20; $LOMAKE = mysql_real_escape_string($_GET["l"]); $LOMAKE2 = mysql_real_escape_string($_POST["lomake"]); after a few more lines... elseif ($LOMAKE2 == "etusivu"){ #Etusivun muokkaus $teksti = stripslashes($_POST["teksti"]); $f = fopen("etusivu.php", "w"); fwrite($f, $teksti); fclose($f); } elseif ($LOMAKE == "etusivu"){ #Etusivun muokkaus echo "<h1>Edit home page</h1>"; $f = file("etusivu.php"); echo "<form action='$KOHDE' method='post'> <textarea name='teksti' cols='$TEXTAREA_W' rows='$TEXTAREA_H'>"; for ($i = 0; $i < count($f); $i++){ $f[$i] = str_replace("\"", "''", $f[$i]); echo $f[$i]; } echo "</textarea> <input type='hidden' value='etusivu' name='lomake'/> <br><input type='submit' value='Save'/> </form><br/>"; html_ohje(); } I can't see where it has gone wrong. Can anyone help?
  3. <?php $team1 = mysql_real_escape_string($_POST['team1']); $team2 = mysql_real_escape_string($_POST['team2']); $ra = mysql_query("SELECT rp FROM teamstats WHERE team='$team1'"); $rb = mysql_query("SELECT rp FROM teamstats WHERE team='$team2'"); $pa = mysql_real_escape_string($_POST['team1goals']); $pb = mysql_real_escape_string($_POST['team2goals']); $ea = 1.0 / (1.0 + pow(10.0, ($rb - $ra) / 400.0)); $eb = 1.0 / (1.0 + pow(10.0, ($ra - $rb) / 400.0)); if ($pa > $pb){ $team1rank = 60.0 * (1.0 - $ea); $team2rank = 60.0 * (0.0 - $eb); mysql_query("UPDATE teamstats SET gp = gp + 1, w = w + 1, l = l, d = d, gf = gf + '$pa', ga = ga + '$pb', rp = rp + '$team1rank' WHERE team='$team1'"); mysql_query("UPDATE teamstats SET gp = gp + 1, w = w, l = l + 1, d = d, gf = gf + '$pb', ga = ga + '$pa', rp = rp + '$team2rank' WHERE team='$team2'"); } elseif ($pa < $pb){ $team1rank = 60.0 * (0.0 - $ea); $team2rank = 60.0 * (1.0 - $eb); mysql_query("UPDATE teamstats SET gp = gp + 1, w = w, l = l + 1, d = d, gf = gf + '$pa', ga = ga + '$pb', rp = rp + '$team1rank' WHERE team='$team1'"); mysql_query("UPDATE teamstats SET gp = gp + 1, w = w + 1, l = l, d = d, gf = gf + '$pb', ga = ga + '$pa', rp = rp + '$team2rank' WHERE team='$team2'"); } elseif ($pa == $pb){ $team1rank = 60.0 * (0.5 - $ea); $team2rank = 60.0 * (0.5 - $eb); mysql_query("UPDATE teamstats SET gp = gp + 1, w = w, l = l, d = d + 1, gf = gf + '$pa', ga = ga + '$pb', rp = rp + '$team1rank' WHERE team='$team1'"); mysql_query("UPDATE teamstats SET gp = gp + 1, w = w, l = l, d = d + 1, gf = gf + '$pb', ga = ga + '$pa', rp = rp + '$team2rank' WHERE team='$team2'"); } ?>
  4. even without the mysql_result()'s which I realise now I don't need it still doesn't work.
  5. I wrote an ELO calculator but somewhere it's going wrong. Not to insult anyones intelligence but the main jist is K*(S-E) where K is the K factor, which I've set to 60.00 S depends on the outcome, 1 for a win, 0.5 for draw, 0 for loss. E is the calculated rank change: E=1/(1+10^((B-A)/400)) where A = team A rank and B = team B rank. So I then went about writing my calculator. Here's what I have: <?php $team1 = mysql_real_escape_string($_POST['team1']); $team2 = mysql_real_escape_string($_POST['team2']); $ra = mysql_query("SELECT rp FROM teamstats WHERE team='$team1'"); $rb = mysql_query("SELECT rp FROM teamstats WHERE team='$team2'"); $pa = mysql_real_escape_string($_POST['team1goals']); $pb = mysql_real_escape_string($_POST['team2goals']); $ea = 1.0 / (1.0 + pow(10.0, ($rb - $ra) / 400.0)); $eb = 1.0 / (1.0 + pow(10.0, ($ra - $rb) / 400.0)); if ($pa > $pb){ $team1rank = mysql_result($ra, $team1); + 60.0 * (1.0 - $ea); $team2rank = mysql_result($rb, $team2); + 60.0 * (0.0 - $eb); mysql_query("UPDATE teamstats SET gp = gp + 1, w = w + 1, l = l, d = d, gf = gf + '$pa', ga = ga + '$pb', rp = rp + '$team1rank' WHERE team='$team1'"); mysql_query("UPDATE teamstats SET gp = gp + 1, w = w, l = l + 1, d = d, gf = gf + '$pb', ga = ga + '$pa', rp = rp + '$team2rank' WHERE team='$team2'"); } elseif ($pa < $pb){ $team1rank = mysql_result($ra, $team1); + 60.0 * (0.0 - $ea); $team2rank = mysql_result($rb, $team2); + 60.0 * (1.0 - $eb); mysql_query("UPDATE teamstats SET gp = gp + 1, w = w, l = l + 1, d = d, gf = gf + '$pa', ga = ga + '$pb', rp = rp + '$team1rank' WHERE team='$team1'"); mysql_query("UPDATE teamstats SET gp = gp + 1, w = w + 1, l = l, d = d, gf = gf + '$pb', ga = ga + '$pa', rp = rp + '$team2rank' WHERE team='$team2'"); } elseif ($pa == $pb){ $team1rank = mysql_result($ra, $team1); + 60.0 * (0.5 - $ea); $team2rank = mysql_result($rb, $team2); + 60.0 * (0.5 - $eb); mysql_query("UPDATE teamstats SET gp = gp + 1, w = w, l = l, d = d + 1, gf = gf + '$pa', ga = ga + '$pb', rp = rp + '$team1rank' WHERE team='$team1'"); mysql_query("UPDATE teamstats SET gp = gp + 1, w = w, l = l, d = d + 1, gf = gf + '$pb', ga = ga + '$pa', rp = rp + '$team2rank' WHERE team='$team2'"); } ?> For some reason, if both teams have a rank of 1000.00 and team A beats team B, instead of team A gaining +30.00 and team B losing -30.00, team A's rank changed to 1037.48 and team B's rank to 972.52. I can't find out why. Thanks in advance.
  6. There's one that I've found...but I'm just struggling applying it to what I'm doing. The idea is to have x number of teams, all starting with 1000 Ranking points. If team A plays team B and wins 1-0, team A should increase by 30 points, and team B should decrease by 30 points? (I think.. ) Then to rank the teams based on their points. The main problem is, I'd like to use a form to edit the teams. I've got as far as a drop down menu to choose the teams, and then Home goals and Away goals. It will already define what is a win/draw/loss. The Calculator code is: <?php class elo_calculator { public function rating($S1,$S2,$R1,$R2) { if (empty($S1) OR empty($S2) OR empty($R1) OR empty($R2)) return null; if ($S1!=$S2) { if ($S1>$S2) { $E=120-round(1/(1+pow(10,(($R2-$R1)/400)))*120); $R['R3']=$R1+$E; $R['R4']=$R2-$E; } else { $E=120-round(1/(1+pow(10,(($R1-$R2)/400)))*120); $R['R3']=$R1-$E; $R['R4']=$R2+$E; }} else { if ($R1==$R2) { $R['R3']=$R1; $R['R4']=$R2; } else { if($R1>$R2) { $E=(120-round(1/(1+pow(10,(($R1-$R2)/400)))*120))-(120-round(1/(1+pow(10,(($R2-$R1)/400)))*120)); $R['R3']=$R1-$E; $R['R4']=$R2+$E; } else { $E=(120-round(1/(1+pow(10,(($R2-$R1)/400)))*120))-(120-round(1/(1+pow(10,(($R1-$R2)/400)))*120)); $R['R3']=$R1+$E; $R['R4']=$R2-$E; }}} $R['S1']=$S1; $R['S2']=$S2; $R['R1']=$R1; $R['R2']=$R2; $R['P1']=((($R['R3']-$R['R1'])>0)?"+".($R['R3']-$R['R1'])$R['R3']-$R['R1'])); $R['P2']=((($R['R4']-$R['R2'])>0)?"+".($R['R4']-$R['R2'])$R['R4']-$R['R2'])); return $R; }} ?>
  7. this is confusing me a lot to clear it up, I could post some examples of what I'm trying to do http://ohl-liiga.net/index.php?sivu=joukkueet&id=32 (sivu=page and joukkueet=team) http://www.kiekkoliiga.net/tilastot/?tilasto=pelaaja&id=934 (tilastot=statistics, pelaaja=player)
  8. I dont need two cases. I'm using 1 generic case. $_GET is defining what the case is. So if I search for /stats.php?type=team&team=UK, it will display all team statistics for the team UK, and the same for any other team. What I need to do now is to be able to change type to player, and for it to do the same for the player chosen.
  9. basically, what I'm trying to do is make it so that the URL reads /stats.php?type=team&team=UK or /stats.php?type=player&player=shmeeg depending on "type", different information will be displayed. if type=player, then player statistics will be displayed, eg. if type=team, then team stats will be displayed eg.
  10. i now have a whole host of errors...i'm a little bit lost here's the whole piece of code: <?php $team = $_GET['team']; switch ($team){ case "$team": $result = mysql_query("SELECT * FROM players WHERE team='$team' ORDER BY total DESC") or die(mysql_error()); echo "<table>"; echo "<tr> <th>player name</th> <th>appearances</th> <th>goals</th> <th>assists</th> <th>total</th> <th>points/match</th> <th># motm</th> </tr>"; while($row = mysql_fetch_array( $result )) { echo "<tr><td>"; echo $row['name']; echo "</td><td><center>"; echo $row['apps']; echo "</center></td><td><center>"; echo $row['goals']; echo "</center></td><td><center>"; echo $row['assists']; echo "</center></td><td><center>"; echo $row['total']; echo "</center></td><td><center>"; echo $row['ppm']; echo "</center></td><td><center>"; echo $row['motm']; echo "</center></td></tr>"; } echo "</table>"; break; } $player = $_GET['name']; switch ($player){ case "$player": $result2 = mysql_query("SELECT * FROM players WHERE name='$player'") or die(mysql_error()); echo "name:"; echo $_GET["name"]; echo "<br />"; echo "nation:"; echo $_GET["team"]; echo "<br />"; break; } ?> i really am lost
  11. so it would be easier to do the addition before it is processed in to the table? also, with the INSERT INTO, is there such a thing as ADD INTO? so when statistics are being updated, if they select the player, then how many goals/assists they had in the match and it would add it to their current ones? rather than using UPDATE
  12. ya, its me again... basically, im using $_GET so that players can bookmark pages for easy access, for example, stats.php?type=player&player=shmeeg (where obviously it only displays my statistics) however, my code works up to a point. im using a switch case for type=team&team=$team heres the code (it's working fine) <?php $team = $_GET['team']; switch ($team){ case "$team": $result = mysql_query("SELECT * FROM players WHERE team='$team' ORDER BY total DESC") or die(mysql_error()); echo "<table>"; echo "<tr> <th>player name</th> <th>appearances</th> <th>goals</th> <th>assists</th> <th>total</th> <th>points/match</th> <th># motm</th> </tr>"; while($row = mysql_fetch_array( $result )) { echo "<tr><td>"; echo $row['name']; echo "</td><td><center>"; echo $row['apps']; echo "</center></td><td><center>"; echo $row['goals']; echo "</center></td><td><center>"; echo $row['assists']; echo "</center></td><td><center>"; echo $row['total']; echo "</center></td><td><center>"; echo $row['ppm']; echo "</center></td><td><center>"; echo $row['motm']; echo "</center></td></tr>"; } echo "</table>"; break; } ?> the next step would be to $player = $_GET['player']; switch ($player){ firstly is this even possible? would i need to use another method or would this actually work?
  13. that solution is also giving me syntax errors. <br />soccerdb > statistics > <?php echo $_GET["type"]; ?> > <?php if( $_GET["type")=="player" ) { echo $row["name"]; } else { echo $row["team"]; } ?> that's the whole piece of code that I have now, error is on line 3 and 5? EDIT: found the error in that one, thanks! it works
  14. is it possible to use addition or division in your MySQL table for a specific row? I have the rows: id, name, team, appearances, goals, assists, total, points/match, motm what I want to happen is that when I add someones goals and assists, that they would be added together in the row "total" and then for the points/match column to take the value from "total" and divide it by "appearances" also the points/match column I would like to use 2 decimal places, eg. 1.00, 2.33 etc is this possible? if so how would I go about doing it?
  15. ok so I guess I'm not too good at this here's my code: <?php echo $_GET["type"]; ?> > <?php if $_GET["type")=="player" echo $row["name"]; elseif $_GET["type"]=="team" echo $row["team"]; ?> I dont usually use if and elseif statements, infact, it's the first time I ever have tried it. What I'm trying to do is allow users to see where they are, at the top of the page it should look a little something like soccerdb > Statistics > Player(if type=player)/Team(if type=team) > player name/team name thanks in advance.
×
×
  • 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.