Jump to content

cliftonbazaar

Members
  • Posts

    165
  • Joined

  • Last visited

Contact Methods

  • Website URL
    http://www.cliftonbazaar.com

Profile Information

  • Gender
    Male
  • Location
    Adelaide Hills

cliftonbazaar's Achievements

Regular Member

Regular Member (3/5)

0

Reputation

  1. $teamID=101; #This is the ID of our own team If I have table MATCHES matchID, tournament, homeTeamID, awayTeamID, e.t.c 1, 1, 101, 98 2, 2, 98, 99 3, 3, 101, 100 4, 4, 99, 100 5, 4, 100, 101 and table TOURNAMENTS with the data tournamentID, winner, loser 1, 101, 98 2, 99, 98 3, 101, 100 4, 99, 100 and table TEAMS with data teamID, name 98, Darren 99, Danika 100, Emma 101, James How would I print out the following - "tournamentID, Winners name, losers name" - if the team was involved with the tournament? Print out with this data would be- 1, James, Darren 3, James, Emma 4, Danika, Emma I know that a JOIN is to be used but I can only find if for one link where as I need to link it to both the winner and loser. At the moment my code is, but it doesn't work anymore and doesn't look for the losers name echo "<TR><TH COLSPAN=8><font size='6'>PREVIOUS TOURNAMENTS</TH>"; $tournaments=mysql_query(" SELECT tournament FROM matches WHERE homeTeamID='$teamID' or awayTeamID='$teamID' GROUP BY tournament ORDER BY tournament desc "); while($tournament=mysql_fetch_array($tournaments)) { $tournament=$tournament['tournament']; $tournament_details=mysql_fetch_array(mysql_query(" SELECT *.tournament, teamID.teams, name.teams FROM tournaments INNER JOIN teams ON winner.tournament = teamID.teams ")); echo "<TD align='center'>".$tournament_details['tournamentID']."</TD>"; echo "<TD colspan=2>".$tournament_details['winner']."</TD>"; echo "<TD colspan=2>".$tournament_details['loser']."</TD>"; }
  2. Hi, The actual locking of the row of the table is done correctly, but its till runs the code in the WHILE loop, I wish to make it that if the loop is locked the WHILE loop does NOT active.
  3. I have the following piece of code (if anyone can think of a better way then please tell me). mysql_query("BEGIN"); #NOTE that we are only going to load in games that need to be updated so there is no need to set an IF statement if(@$my_team['inGame']) {$my_team_ID = $my_team['inGame'];} else{$my_team_ID=0;} $matches = mysql_query("SELECT * FROM matches WHERE completed=0 and $current_time > updateTime ORDER BY matchID ASC LOCK IN SHARE MODE "); //Get all the matches that need updating while($match = mysql_fetch_array($matches)) { //Go through all the matches that need updating $notes .= "<p>MatchID - ".$match['matchID']." ".$match['homeTeam']." V ".$match['awayTeam']; $updateTime=$match['updateTime']; #Get the updateTime from the match ID include("run_game.php"); #This is the actual file that runs the game $notes .= "<BR>This is the string data".$stringData."<BR>"; #Output it to make sure it works } mysql_query("COMMIT"); # Here the datarecords are released and the transaction is completed This code works fine - the 'matches' database is only updated once; the problem is if it is run from two differant directions then ANOTHER part of the code in run_game.php is run and updated, this is not what I wanted How can I get this query NOT to activate on locked rows? I tried Google but I dont' know what to search for
  4. Hi all, I have the following function that refreshes sections of my code each two seconds - and it works fine. Now I wish for another part to refresh every 1 second, the following code keeps everything refreshing at 2 seconds. I have tried to rename the var to refreshID2 (didn't work ). How do I get this working correctly? //This is our Javascript function that allows us to constantly reload a page if we are involved in a match. $(document).ready(function() { $("#autoRefreshMatchStatus").load('game/gameplay/showCurrentGame.php'); $("#autoRunGame").load('game/gm/rungame/main.php'); $("#currentTime").load('game/functions/current_time.php'); var refreshId = setInterval(function() { $("#autoRefreshMatchStatus").load('game/gameplay/showCurrentGame.php'); $("#autoRunGame").load('game/gm/rungame/main.php'); }, 2000); var refreshId = setInterval(function() { $("#currentTime").load('game/functions/current_time.php'); }, 1000); $.ajaxSetup({ cache: false }); });
  5. Thanks for that - out of all the research I did on google not one site told me Everything works 100% now
  6. So here is my final code - SELECT teamID, SUM(homeGames + awayGames) as gamesPlayed, SUM(homeGames) as homeGames, SUM(awayGames) as awayGames, SUM(homePoints + awayPoints) AS totalPoints, SUM(homePoints) as homePoints, SUM(awayPoints) AS awayPoints, SUM(pointsAgainst) AS pointsAgainst FROM ( SELECT homeTeamID as teamID, tournament, SUM(homePoints) as homePoints, 0 as awayPoints, COUNT(homeTeamID) as homeGames, 0 as awayGames, SUM(awayPoints) as pointsAgainst FROM matches WHERE tournament=$tournament and completed GROUP BY teamID UNION ALL SELECT awayTeamID as teamID, tournament, 0 as homePoints, SUM(awayPoints) AS awayPoints, COUNT(awayTeamID) as awayGames, 0 as homeGames, SUM(homePoints) as pointsAgainst FROM matches WHERE tournament=$tournament and completed GROUP BY teamID ) as t GROUP BY teamID ORDER BY totalPoints DESC, pointsAgainst ASC one problem - it states that all games were played at 'home'. It gets the correct amount of games, but says they were all played at 'home' and none played 'away' - yet it gets the 'home' and 'away' points correct! Output code (PHP) is while($display_ladder = mysql_fetch_array($ladder)){ $notes .= "<br>".$display_ladder['teamID']." - ".$display_ladder['gamesPlayed']." - ".$display_ladder['homeGames']."/".$display_ladder['awayGames']." - ".$display_ladder['totalPoints']." - ".$display_ladder['homePoints']." - ".$display_ladder['awayPoints']." - ".$display_ladder['pointsAgainst']; } so it's not just a simple spelling error in the PHP code.
  7. Sorry about that, it was only after I had it all working that a tester said "but my team hasn't played as many games as his" that I realised that I needed to be able to show the number of games each team has played. Thanks again for the solution
  8. Thanks for all that, how would I go about finding out how many home and away games they have each played (because sometimes not all teams have played the same amount of games). The best I could come up with was SELECT teamID, SUM(homeGames + awayGames) AS gamesPlayed, SUM(homeGames) AS homeGames, SUM(awayGames) AS awayGames, SUM(homePoints + awayPoints) AS totalPoints, SUM(homePoints) as homePoints, SUM(awayPoints) AS awayPoints, SUM(pointsAgainst) AS pointsAgainst FROM ( SELECT COUNT(homeTeamID) AS homeGames, homeTeamID as teamID, SUM(homePoints) as homePoints, 0 AS awayPoints, SUM(awayPoints) as pointsAgainst FROM matches GROUP BY teamID UNION ALL SELECT COUNT(awayTeamID) AS awayGames, awayTeamID as teamID, 0 as homePoints, SUM(awayPoints) AS awayPoints, SUM(homePoints) as pointsAgainst FROM matches GROUP BY teamID ) as t GROUP BY teamID ORDER BY totalPoints DESC, pointsAgainst ASC but it gives an error
  9. If I have the following data in my database (it shows the results of cricket games) - homeTeamID - awayTeamID - homePoints - awayPoints 101 - 96 - 10 - 0 97 - 98 - 2 - 4 100 - 99 - 6 - 0 101 100 - 2 - 0 97 - 99 - 0 - 0 96 - 98 - 0 - 10 How do I put this data into a premisership table that shows the results as (in descending order of points) - Team - total points - home points - away points - points against 98 - 14 - 0 - 14 - 2 101 - 12 - 12 - 0 - 0 100 - 6 - 6 - 0 - 2 97 - 2 - 2 - 0 - 4 99 - 0 - 0 - 0 - 6 96 - 0 - 0 - 0 - 20 I have tried the looooong way by going through each game with a while($match = mysql_fetch_array($tourny_matches)) { //Go through all the matches in the tournament loop but I have manged to trip myelf up three times
  10. I have a game running which allows players to compete against each other. I have now found out that if both players are online at the same time then the server trys to run the same queries at the same time, with differant results that confuses everyone How do I 'Lock' a piece of data so it can only be opened once by the PHP code; but it also needs to be available in 'read only' for other players. Any suggestions would be helpful and a link to a tutorial would be even better James
  11. errrrr ... wow! On both counts Thanks for that, already updated my code and it works fantastic (and a lot easier to read!!)
  12. I currently use long variable names so I know what each one is at a glance, I also use a two dimensional array. In the current piece of code I have tried to tighten it from for($i=1; $i<12; $i++) { $battingPlayer[$battingLineUp[$i]]['energy'] += mt_rand(10, floor($battingPlayer[$battingLineUp[$i]]['fitness']/10+10)); #If energy is low then player gets a bit of it back $bowlingPlayer[$bowlingLineUp[$i]]['energy'] += mt_rand(10, floor($bowlingPlayer[$bowlingLineUp[$i]]['fitness']/10+10)); #If energy is low then player gets a bit of it back if($battingPlayer[$battingLineUp[$i]]['energy'] > $battingPlayer[$battingLineUp[$i]]['fitness']) $battingPlayer[$battingLineUp[$i]]['energy'] = $battingPlayer[$battingLineUp[$i]]['fitness']; #Energy cannot be more than fitness if($bowlingPlayer[$bowlingLineUp[$i]]['energy'] > $bowlingPlayer[$bowlingLineUp[$i]]['fitness']) $bowlingPlayer[$bowlingLineUp[$i]]['energy'] = $bowlingPlayer[$bowlingLineUp[$i]]['fitness']; #Energy cannot be more than fitness } to this for($i=1; $i<12; $i++) { for($j=0; $j<2; $j++) { if($j) {$x = $battingPlayer[$battingLineUp[$i]];} else {$x = $bowlingPlayer[$bowlingLineUp[$i]];} echo "<br>old energy is ".$x['energy']." and now they have "; $x['energy'] -= mt_rand(10, floor($x['fitness']/10+10)); #If energy is low then player gets a bit of it back if($x['energy'] > $x['fitness']) $x['energy'] = $x['fitness']; #Energy cannot be more than fitness echo $x['energy']; } } While the echo statements show an increase in the number($x['energy']) the variable is not increased when it is used with the full variable name! ($battingPlayer[$battingLineUp[$i]]['energy']). I know one method is to use shorter variable names but I'm very happy with how they are
  13. Thanks for that - I'll go and search google for javascript to do this
×
×
  • 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.