Jump to content

Archived

This topic is now archived and is closed to further replies.

ShopMAster

Help with stat program

Recommended Posts

I have a database with two tables.

1st table is called players (this list about 60 players and thier records) This is the code for my statedit page when I need to update a players info as well as add a new player.

[code]<?php



$db = mysql_connect("");

mysql_select_db("",$db);



if ($submit) {

  // here if no ID then adding else were editing

  if ($id) {

    $sql = "UPDATE players SET player_name='$player_name',player_perc='$player_perc',player_win='$player_win',player_loss='$player_loss',player_lastw='$player_lastw',player_lastl='$player_lastl', player_hs='$player_hs',player_div='$player_div',player_rival='$player_rival', player_rp='$player_rp',player_cfl='$player_cfl',player_hc='$player_hc',player_starless='$player_starless',player_nk='$player_nk',player_team='$player_team' WHERE id=$id";

  } else {

    $sql = "INSERT INTO players (player_name,player_perc,player_win,player_loss,player_lastw,player_lastl,player_hs,player_div,player_rival,player_rp,player_cfl,player_hc,player_starless,player_nk,player_team) VALUES ('$player_name','$player_perc','$player_win','$player_loss','$player_lastw','$player_lastl','$player_hs','$player_div','$player_rival','$player_rp','$player_cfl','$player_hc','$player_starless','$player_nk','$player_team')";

  }

  // run SQL against the DB

  $result = mysql_query($sql);

  echo "<font face=Verdana size=2>Record updated/edited! <a href=http://www.><font face=Verdana size=2>Go
Back to List</font></a><p>";

} elseif ($delete) {

    // delete a record

    $sql = "DELETE FROM players WHERE id=$id";    

    $result = mysql_query($sql);

    echo "$sql Record deleted! <a href=http://www.><font face=Verdana size=2>Go
Back to List</font></a><p>";

} else {

  // this part happens if we don't press submit

  if (!$id) {

    // print the list if there is not editing

    $result = mysql_query("SELECT * FROM players ORDER BY player_name",$db);

    while ($myrow = mysql_fetch_array($result)) {


       printf("<font face=Verdana size=2><a href=\"%s?id=%s\">%s</a> \n", $PHP_SELF, $myrow["id"], $myrow["player_name"]);

        printf("<a href=\"http://www.easports.com/sports/madden06/scouting_zone.jsp?player=%s&platform=ps2\" target=_blank> (Stats)</a><br>", $myrow["player_name"]);
                        
    //  printf("<a href=\"%s?id=%s&delete=yes\">(DELETE)</a><br>", $PHP_SELF, $myrow["id"]);

    

    }

  }



  ?>

  <P>

  <a href="<?php echo $PHP_SELF?>">ADD A RECORD</a>

  <P>

  <form method="post" action="<?php echo $PHP_SELF?>">

  <?php



  if ($id) {

    // editing so select a record

    $sql = "SELECT * FROM players WHERE id=$id";

    $result = mysql_query($sql);

    $myrow = mysql_fetch_array($result);

    $id = $myrow["id"];

    $player_name = $myrow["player_name"];

    $player_perc = $myrow["player_perc"];

    $player_win = $myrow["player_win"];

    $player_loss = $myrow["player_loss"];

    $player_lastw = $myrow["player_lastw"];

    $player_lastl = $myrow["player_lastl"];

    $player_hs = $myrow["player_hs"];

    $player_div = $myrow["player_div"];

    $player_rival = $myrow["player_rival"];

    $player_rp = $myrow["player_rp"];

    $player_cfl = $myrow["player_cfl"];
  
    $player_hc = $myrow["player_hc"];

    $player_starless = $myrow["player_starless"];
    
    $player_nk = $myrow["player_nk"];

    $player_team = $myrow["player_team"];

    // print the id for editing



    ?>

    <input type=hidden name="id" value="<?php echo $id ?>">

    <?php

  }



  ?>

  Player's name:<input type="Text" name="player_name" size="25" value="<?php echo $player_name ?>"><br>

  Player's %:<input type="Text" name="player_perc" value="<?php echo $player_perc ?>"><br>

  Player's wins:<input type="Text" name="player_win" value="<?php echo $player_win ?>"><br>

  Player's losses:<input type="Text" name="player_loss" value="<?php echo $player_loss ?>"><br>

  Last Win:<input type="Text" name="player_lastw" value="<?php echo $player_lastw ?>"><br>

  Last Loss:<input type="Text" name="player_lastl" value="<?php echo $player_lastl ?>"><br>

  Home Security:<input type="Text" name="player_hs" value="<?php echo $player_hs ?>"><br>

  Division:<input type="Text" name="player_div" value="<?php echo $player_div ?>"><br>

  Rival:<input type="Text" name="player_rival" value="<?php echo $player_rival ?>"><br>

  Run/Pass:<input type="Text" name="player_rp" value="<?php echo $player_rp ?>"><br>

  CFL:<input type="Text" name="player_cfl" value="<?php echo $player_cfl ?>"><br>

  Hard-Core:<input type="Text" name="player_hc" value="<?php echo $player_hc ?>"><br>

  Starless:<input type="Text" name="player_starless" value="<?php echo $player_starless ?>"><br>
  
  No Kicking:<input type="Text" name="player_nk" value="<?php echo $player_nk ?>"><br>

  Team:<input type="Text" name="player_team" value="<?php echo $player_team ?>"><br>

  <input type="Submit" name="submit" value="Enter information">

  </form>



<?php



}



?>
[/code]

The 2nd table is called random_games This table hold games played by the players. Players fill out a form and it goes to this random_games table. This randomgameedit.php page allows me to look at the games and then delete them after I update the stats using the above page. Here is that page:

[code]<?php



$db = mysql_connect("");

mysql_select_db("",$db);



if ($submit) {

  // here if no ID then adding else we're editing

  if ($id) {

    $sql = "UPDATE random_games SET random_winner='$random_winner',random_wscore='$random_wscore',random_loser='$random_loser',random_lscore='$random_lscore',random_comment='$random_comment' WHERE id=$id";

  } else {

    $sql = "INSERT INTO random_games (random_winner,random_wscore,random_loser,random_lscore,random_comment) VALUES ('$random_winner','$random_wscore','$random_loser','$random_lscore','$random_comment')";

     }

  // run SQL against the DB

  $result = mysql_query($sql);

  echo "<font face=Verdana size=2>Record updated/edited! <a href=http://www.><font face=Verdana size=2>Go
Back to List</font></a><p>";

} elseif ($delete) {

    // delete a record

    $sql = "DELETE FROM random_games WHERE id=$id";    

    $result = mysql_query($sql);

    echo "$sql Record deleted! <a href=http://www.><font face=Verdana size=2>Go
Back to List</font></a><p>";

} else {

  // this part happens if we don't press submit

  if (!$id) {

    // print the list if there is not editing

    $result = mysql_query("SELECT * FROM random_games ORDER BY random_winner, id",$db);

    while ($myrow = mysql_fetch_array($result)) {


       printf("<font face=Verdana size=2><a href=\"%s?id=%s\">%s def %s</a> \n", $PHP_SELF, $myrow["id"], $myrow["random_winner"], $myrow["random_loser"]);

      printf("<a href=\"%s?id=%s&delete=yes\">(DELETE)</a><br>", $PHP_SELF, $myrow["id"]);

    

    }

  }



  ?>

  <P>

  <a href="<?php echo $PHP_SELF?>">ADD A RECORD</a>

  <P>

  <form method="post" action="<?php echo $PHP_SELF?>">

  <?php



  if ($id) {

    // editing so select a record

    $sql = "SELECT * FROM random_games WHERE id=$id";

    $result = mysql_query($sql);

    $myrow = mysql_fetch_array($result);

    $id = $myrow["id"];

    $random_winner = $myrow["random_winner"];

    $random_loser = $myrow["random_loser"];

    $random_wscore = $myrow["random_wscore"];

    $random_lscore = $myrow["random_lscore"];

    $random_comment = $myrow["random_comment"];

    // print the id for editing



    ?>

    <input type=hidden name="id" value="<?php echo $id ?>">

    <?php

  }



  ?>&nbsp;<br>

  Winner:<input type="Text" name="random_winner" value="<?php echo $random_winner ?>" size="20"><input type="Text" name="random_wscore" value="<?php echo $random_wscore ?>" size="2">
  winning score<br>
  <br>
  defeats<br>
  <br>

  Loser:<input name="random_loser" value="<?php echo $random_loser ?>" size="20"><input name="random_lscore" value="<?php echo $random_lscore ?>" size="2">
  losing score<br>
  <br>
  Comment:<br>

  <input name="random_comment" value="<?php echo $random_comment ?>" size="99"><br>

  <br>

  <input type="Submit" name="submit" value="Enter information">

  </form>



<?php



}



?>
[/code]

So what I need help with is I want to add an "UPDATE" function at the end of every random game so that the players wins and losses, as well as last_win, and last_loss are updated so I never have to edit each player myself. If I could do this it would take a great load off of having to update stats as there are over 100 games each day.

Please help. How do you update one table by pulling info from another table.

Thanks.

Shopmaster

Share this post


Link to post
Share on other sites

×

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.