Jump to content

ameriblog

Members
  • Posts

    28
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

ameriblog's Achievements

Member

Member (2/5)

0

Reputation

  1. Here's what I have: SCHOOL W L The string is in a loop, from my query: <? $ratings3_rs = $conn->Execute ( "SELECT * FROM ncaa_tm ORDER BY team_mpirank ASC" ) or die ( $conn->ErrorMsg() ); while ( ! $ratings3_rs->EOF ) { <? echo "$name"; ?> <? echo "$won"; ?> <? echo "$lost"; ?> $ratings3_rs->MoveNext(); } ?> The $name variable is the one I need to add spaces after.
  2. hm, okay. the reason i ask, and maybe there is a better way all together to do this is I have a list that I want in preformatted text that lists schools, then their win and loss record. the length's of the school's name goes from 3 to 19, there are 120 of them. since 19 is the longest i want it displayed, then 3 spaces will separate it and the W column. so if there is a string in the loop that is 3, i need to make sure there 16 spaces after that string when it is displayed.
  3. Thanks, my question is where do I set the max number? If 19 is the longest string, where do I set it so that 19 is the max?
  4. I can use strlen() to get the length of a string/variable. What I am trying to accomplish is adding a number of spaces after the variable displays on the screen based on how long it is. For example if my longest strlen() = 6, then for the strings where strlen() = 3, I want to add ' ' after it, where strlen() = 4 I want to add ' ' etc. Thanks
  5. Thanks, for some reason I was thinking || instead of &&, bad day Thanks again.
  6. I have an IF statement in my code, what I am trying to accomplish is get IF the variable is 1-16. Right now I have it set to be <= 16, but it is getting results that are 0 that I don't want. if ( $team2_rs->Fields("team_mpirk") <= 16 ) { }
  7. I have a variable and I want to run an if clause to display one result if the variable is an odd number or display a different results if it is even. if ( $schedule_rs->Fields("team1") == 1 ) { echo "odd"; } else { echo "even"; }
  8. I am just going back to my old structure. I was told that it was only luck that I managed to get things to work properly with the way I had originally had it setup and that if I changed it things would be easier, but that's not my experience so far!
  9. I need help with a query used to compute sports ratings. Up until this week I had this DB structure: TABLE games gameID game_date team1 (fk) team1_score team2 (fk) team2_score TABLE teams teamID team_name team_ww I was able to compute the ratings by running a loop through every game and calculating the ratings on a game by game basis. Over the weekend a fellow PHP programmer urged me to correct my DB structure to database normalization. So my new table structure is: TABLE games gameID game_date TABLE games_info infoID gameID (fk) teamID (fk) team_score TABLE teams teamID team_name team_ww I tried to correct my code to correctly calculate the ratings, as the previous version had done. Not only are they not computing correctly, it is also taking longer than 10 minutes and my connection times out and it stops. I have the following code that is what I am using now: $weighted_rs = $conn->Execute ( "SELECT ncaa_gm.gameID, ncaa_gm.game_date, ncaa_gm.game_year, game_fixed, infoID, ncaa_gm_info.gameID, ncaa_gm_info.teamID, ncaa_gm_info.team_score FROM ncaa_gm_info, ncaa_gm WHERE ncaa_gm_info.gameID = ncaa_gm.gameID AND game_year = " . $_GET['year'] . " AND game_fixed = 1 ORDER BY ncaa_gm_info.infoID ASC" ) or die ( $conn->ErrorMsg() ); while ( ! $weighted_rs->EOF ) { // TEAM 1 INFO $team_rs = $conn->Execute ( "SELECT teamID, team_gp, team_mpi, team_ww FROM ncaa_tm WHERE teamID = " . $weighted_rs->Fields("teamID") . "" ) or die ( $conn->ErrorMsg() ); $team = $team_rs->Fields("teamID"); $team_gp = $team_rs->Fields("team_gp"); $team_ww = $team_rs->Fields("team_ww"); $opp_rs = $conn->Execute ( "SELECT ncaa_tm.teamID, team_gp, team_mpi, team_ww, ncaa_gm_info.teamID, gameID, team_score FROM ncaa_gm_info, ncaa_tm WHERE gameID = " . $weighted_rs->Fields("gameID") . " AND ncaa_gm_info.teamID != " . $weighted_rs->Fields("teamID") . " AND ncaa_gm_info.teamID = ncaa_tm.teamID" ) or die ( $conn->ErrorMsg() ); $opp_gp = $opp_rs->Fields("team_gp"); $opp_mpi = $opp_rs->Fields("team_mpi"); // IF TEAM WON if ( $weighted_rs->Fields("team_score") > $opp_rs->Fields("team_score") ) { $weighted_win = $team_ww + $opp_mpi + 1; $sql = "UPDATE ncaa_tm SET team_ww = $weighted_win WHERE teamID = $team"; $add_weighted_rs = $conn->Execute($sql) or die ( $conn->ErrorMsg() ); } // IF TEAM LOST if ( $weighted_rs->Fields("team_score") < $opp_rs->Fields("team_score") ) { $weighted_win = $team_ww + $opp_mpi - 1; $sql = "UPDATE ncaa_tm SET team_ww = $weighted_win WHERE teamID = $team"; $add_weighted_rs = $conn->Execute($sql) or die ( $conn->ErrorMsg() ); } $weighted_rs->MoveNext(); } My previous structure was the code would loop through all games, then would calculate the record for team1 and update the db, then calculate the record for team2 and update the db. I'd like to set this up to operate similarly...
  10. Actually, my server is doing odd stuff right now. I have stopped the program, so it isn't running/updating the WL, but if I go to the results page and just keep reloading it, the results change every time I reload it, like the updating file is running.
  11. Tried id. Didn't really help. I think I need to change my queries up a bit. I think the $record_rs query needs to get only the games, then within the loop the $team_rs query and $opp_rs query should get the info from wvhs_gm_info db where gameID is equal to the gameID from $record_rs and team.teamID = wvhs_gm_info.teamID. I tried a variation of this and it didn't work. It wasn't computing the records correctly...
  12. I have a query that is used to calculate W/L records for teams based on games. I have three tables: TABLE wvhs_gm gameID (pk) game_date game_year game_fixed TABLE wvhs_gm_info infoID (pk) gameID (foreign key) teamID (foreign key) team_score TABLE wvhs_tm teamID team_name team_won team_lost team_gp etc I have the following code that I use to calculate the record, but it takes forever, a good 5+ minutes. I have 11543 or so games in the database and that means I have over 23000 info entries in the database. The reason there is so many is all scores from 2004, 2005, 2006 are in there and I am starting to add 2007. This is so I can keep historical records and run retro-ratings from these games. Here's the code: // START CLEARING W, L, T, ETC $reset_rs = $conn->Execute ( "SELECT * FROM ncaa_tm WHERE team_year = " . $_GET['year'] . " ORDER BY teamID DESC" ) or die ( $conn->ErrorMsg() ); echo "Starting clearing fields ..."; while ( ! $reset_rs->EOF ) { $sql = "UPDATE ncaa_tm SET team_mpirankold = " . $reset_rs->Fields("team_mpirank") . ", team_won = 0, team_lost = 0, team_gp = 0, team_cwon = 0, team_clost = 0, team_cgp = 0, team_pf = 0, team_pa = 0, team_ww = 0, team_sostotal = 0, team_awp = 0.5 WHERE teamID = " . $reset_rs->Fields("teamID") . ""; $add_rating_rs = $conn->Execute($sql) or die ( $conn->ErrorMsg() ); $reset_rs->MoveNext(); } echo "Complete!<br><hr><br>"; // END CLEARING W, L, T, ETC // // START CALCULATING W, L $record_rs = $conn->Execute ( "SELECT * FROM ncaa_gm_info, ncaa_gm WHERE ncaa_gm_info.gameID = ncaa_gm.gameID AND game_year = " . $_GET['year'] . " AND game_fixed = 1 ORDER BY infoID ASC" ) or die ( $conn->ErrorMsg() ); echo "Start calculating record ... "; while ( ! $record_rs->EOF ) { $team_rs = $conn->Execute ( "SELECT * FROM ncaa_tm WHERE teamID = " . $record_rs->Fields("teamID") . "" ) or die ( $conn->ErrorMsg() ); $team = $team_rs->Fields("teamID"); $team_gp = $team_rs->Fields("team_gp"); $team_won = $team_rs->Fields("team_won"); $team_lost = $team_rs->Fields("team_lost"); $team_pf = $team_rs->Fields("team_pf"); $team_pa = $team_rs->Fields("team_pa"); $team_cwon = $team_rs->Fields("team_cwon"); $team_clost = $team_rs->Fields("team_clost"); $team_cgp = $team_rs->Fields("team_cgp"); $team_conf = $team_rs->Fields("team_conf"); $opp_rs = $conn->Execute ( "SELECT * FROM ncaa_gm_info, ncaa_tm WHERE gameID = " . $record_rs->Fields("gameID") . " AND ncaa_gm_info.teamID != " . $record_rs->Fields("teamID") . " AND ncaa_gm_info.teamID = ncaa_tm.teamID" ) or die ( $conn->ErrorMsg() ); $opp_conf = $team_rs->Fields("team_conf"); // IF TEAM WON if ( $record_rs->Fields("team_score") > $opp_rs->Fields("team_score") ) { $team_gp = $team_gp + 1; $team_won = $team_won + 1; $team_pf = $team_pf + $record_rs->Fields("team_score"); $team_pa = $team_pa + $opp_rs->Fields("team_score"); if ( $team_rs->Fields("team_conf") == $opp_rs->Fields("team_conf") ) { $team_cgp = $team_cgp + 1; $team_cwon = $team_cwon + 1; } else { $team_cgp = $team_cgp + 0; $team_cwon = $team_cwon + 0; } $sql = "UPDATE ncaa_tm SET team_cwon = $team_cwon, team_cgp = $team_cgp, team_pf = $team_pf, team_pa = $team_pa, team_gp = $team_gp, team_won = $team_won WHERE teamID = $team"; $add_rating_rs = $conn->Execute($sql) or die ( $conn->ErrorMsg() ); } // IF TEAM LOST if ( $opp_rs->Fields("team_score") > $record_rs->Fields("team_score") ) { $team_gp = $team_gp + 1; $team_lost = $team_lost + 1; $team_pf = $team_pf + $record_rs->Fields("team_score"); $team_pa = $team_pa + $opp_rs->Fields("team_score"); if ( $team_rs->Fields("team_conf") == $opp_rs->Fields("team_conf") ) { $team_cgp = $team_cgp + 1; $team_clost = $team_clost + 1; } else { $team_cgp = $team_cgp + 0; $team_clost = $team_clost + 0; } $sql = "UPDATE ncaa_tm SET team_clost = $team_clost, team_cgp = $team_cgp, team_pf = $team_pf, team_pa = $team_pa, team_gp = $team_gp, team_lost = $team_lost WHERE teamID = $team"; $add_rating_rs = $conn->Execute($sql) or die ( $conn->ErrorMsg() ); } $record_rs->MoveNext(); } echo "Complete!<br><hr><br>"; // END CALCULATING W, L What I would like to do is speed up the process, if possible. I have about 3800 games per year...
  13. I have the following code, trying to get content from a text file and inserting it into the database. Right now, for some reason, the code is only entering the first line from the .txt file and not the rest of the lines... <?php require ( "dbconnex.php" ); $lines = file('wv_scores.txt'); foreach ($lines as $line) { $team = $score = array(); $teamscore = explode(',', $line); foreach ($teamscore as $k=>$ts) { $x = strrpos($ts, ' '); $team[$k] = trim(substr($ts,0,$x)); $score[$k] = trim(substr($ts,$x)); } $games_rs = $conn->Execute ( "INSERT INTO wvhs_gm (team1_name, team1_score, team2_name, team2_score, game_year, team1, team2, game_extra, game_extra1, game_date, game_fixed) VALUES ('$team[0]', '$score[0]', '$team[1]', '$score[1]', 2007, 0, 0, 'NA', 'NA', '" . $_GET['date'] . "', 0)" ) or die ( $conn->ErrorMsg() ); $add_rating_rs = $conn->Execute($sql) or die ( $conn->ErrorMsg() ); } ?>
  14. Thanks, both of you. I have this code, for some reason it is only entering the first line into the database: <?php require ( "dbconnex.php" ); $lines = file('wv_scores.txt'); foreach ($lines as $line) { $team = $score = array(); $teamscore = explode(',', $line); foreach ($teamscore as $k=>$ts) { $x = strrpos($ts, ' '); $team[$k] = trim(substr($ts,0,$x)); $score[$k] = trim(substr($ts,$x)); } $games_rs = $conn->Execute ( "INSERT INTO wvhs_gm (team1_name, team1_score, team2_name, team2_score, game_year, team1, team2, game_extra, game_extra1, game_date, game_fixed) VALUES ('$team[0]', '$score[0]', '$team[1]', '$score[1]', 2007, 0, 0, 'NA', 'NA', '" . $_GET['date'] . "', 0)" ) or die ( $conn->ErrorMsg() ); $add_rating_rs = $conn->Execute($sql) or die ( $conn->ErrorMsg() ); } ?>
×
×
  • 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.