Jump to content

cliftonbazaar

Members
  • Posts

    165
  • Joined

  • Last visited

Everything posted by cliftonbazaar

  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
  14. I have a page that echo's 10 questions so the user can choose one, what I want is a one second delay between each question being displayed, I have tried sleep() in the loop but this doesn't work My current code is for($i=0; $i < 10; $i++) { sleep(1); echo "<tr><td style='text-align:center;'>$i</td> <td colspan=9>"; ?><input type="button" value="<?php echo $rows[$_SESSION['questions'][$i]]["question"]; ?>" onclick="location.href='game/update.php?gameID=<?php echo $player['current_game_id']."&gamequestion=".$rows[$_SESSION['questions'][$i]]["question_no"]."&runs=$runs"; ?>'"><?php echo "</td></tr>"; } NOTE that if I take sleep(1) out everything works fine but when I put it in it only gives a ten second delay after I have clicked a button that appears from in the loop.
  15. Thanks for all the replies, unfortunately I have to go out now I will try all the options that were suggested, if nothing works I think I'll have to change things
  16. Table name : sleuth_game Columns : playerID, puzzleID (primary key), puzzle_level, total_time, final_score Data: 101, 1, 4, 123, 50 102, 2, 4, 215, 30 101, 3, 4, 198, 60 102, 4, 4, 186, 40 103, 5, 4, 196, 45 101, 6, 4, 187, 40 103, 7, 4, 164, 55 101, 8, 4, 258, 25 103, 9, 4, 177, 35 and I want the AVERAGE of the HIGHEST 3 scores for each person(playerID). So playedID of 101 would have the three highest scores of 50, 60 & 40 (even though they had 4 scores only their top three count) and the average would be 50. playerID 102 only has 2 scores so they are not included. playerID has 45, 55 & 35 so their average would be 45. So the expected output would be : 101, 50 103, 45
  17. Hi Jessica, Thanks for your reply, I nearly have it working from yoru code but I need the three highest scores. James
  18. Hi, I am writing code to find the average of each players highest 3 scores (and they must have 3 scores minimum), So if the database says James 50 Emma 30 James 60 Emma 40 Darren 45 James 40 Darren 55 James 25 Darren 35 Then I would like to find the highest averages of the top three scores; so James would be 50+60+40 (only highest 3 scores) = 50 and Darren would be 45+55+35=45 while Emma would not be included because she only has two scores. James
  19. Thanks for the link, now have it in my favorites
  20. I am trying to create a vertical navigation drop down menu where, if you hover the mouse over the parent, a drop down sub-menu appears on the right. With the code I have the sub menu comes up OVER the parent menu at the top left of the navigation DIV; I want the sub menu to appear on the right of the parent menu and also the top sub menu to appear next to the parent. HTML code is <li><a href='games.php'>Games</a> <ul> <li><a href='games/crivia.php'>Crivia</a></li> <li><a href='games/sleuth.php'>Super Sleuth</a></li> </ul> </li> while my full CSS looks like #navigation { width: 12em; border-right: 1px solid #000; padding: 1em 0 1em 0; margin-top: 1em; margin-bottom: 1em; font-family: 'Trebuchet MS', 'Lucida Grande', Verdana, Lucida, Geneva, Helvetica, Arial, sans-serif; background-color: black; color: #333; cursor: pointer; display:block; position:relative; } #navigation ul { list-style: none; margin: 0; padding: 0; border: none; } #navigation li { border-bottom: 1px solid #90bade; margin: 0; } #navigation li a,active { display: block; padding: 5px 5px 5px 0.5em; border-left: 10px solid black; border-right: 10px solid red; background-color: maroon; color: #fff; text-decoration: none; width: 100%; } #navigation li a,active { width: auto; } #navigation li a:hover { border-left: 10px solid black; border-right: 10px solid maroon; background-color: grey; color: #fff; position: relative; } #navigation li active { border-left: 10px solid black; border-right: 10px solid red; background-color: red; color: black; } #navigation ul ul{ position:absolute; display:none; } #navigation ul li:hover ul{ position:absaloute; display:block; top:0; }
  21. I have just upgraded to the latest version and now some of the tables in my databases will not display in phpmyadmin, the .frm files are all in the folder still but some are being displayed yet others aren't! When I run php code the tables the phpmyadmin can display will run, but the tables that phpmyadmin can't display cannot be used by the code. If I try to create the table in phpmyadmin it gives me an error saying that "database.newtable doesn't exist", even though I'm creating it so it should exist now!
  22. Thanks for that, unfortunately I have to goto work but I will fix it as soon as I get home.
  23. Thanks for that, I thought they could
×
×
  • 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.