• Questions That Don't Need Their Own Thread v3
    4,068 replies, posted
  • hey guys, i have a MySQL table full of 'games' - each game may only be played by a given user *once* - so i need to store a list of previous players per-game. when a player requests a new game, i need to select a game which the user has not played before, then add the player to this list before the game is sent to him/her. i'm a complete MySQL newbie, so can someone suggest the proper table layout to manage a list like this? and how would i query for a game that doesn't have a certain player in its list of previous players?
  • [QUOTE=icantread49;35539473]hey guys, i have a MySQL table full of 'games' - each game may only be played by a given user *once* - so i need to store a list of previous players per-game. when a player requests a new game, i need to select a game which the user has not played before, then add the player to this list before the game is sent to him/her. i'm a complete MySQL newbie, so can someone suggest the proper table layout to manage a list like this? and how would i query for a game that doesn't have a certain player in its list of previous players?[/QUOTE] Have a table called something like games_played or whatever you want like this [code] |user_id | game_id | +--------+---------+ |1 | 2 | +--------+---------+ |1 | 3 | +--------+---------+ |2 | 1 | +--------+---------+ |2 | 3 | +--------+---------+ |3 | 1 | +--------+---------+ [/code] then say you wanted all the players who have played game_id 3 you could do [b]"SELECT 'user_id' FROM 'games_played' WHERE 'game_id' = 3"[/b] or say you wanted all the games a specific player has played for example user 1 [b]"SELECT ''game_id' FROM 'games_played' WHERE 'user_id' = 1"[/b] I'm no expert but this is how i would go about it, hope this helps
  • This is a question regarding Ruby: [CODE]@wattedoens.each do |wattedoen| test = wattedoen.naam.downcase! %> test = <%= test %>, <%= wattedoen.naam %> <br/><br/> <% if(test == $test) redirect end end[/CODE] Is what I have. For some reason it shows the name of the first object, and then for the second object, there is a value before I downcase it, but no value in the "test" variable after i downcase. Output: test = tussen_2_voertuigen, tussen_2_voertuigen test = , fietser_of_voetganger (Words are Dutch and so are some of the variable names, but you get the picture) [editline]12th April 2012[/editline] [QUOTE=Spero78;35539633] I'm no expert but this is how i would go about it, hope this helps[/QUOTE] I've done enough mysql at my school to see this is the correct way of doing it.
  • [QUOTE=Spero78;35539633]Have a table called something like games_played or whatever you want like this [code] |user_id | game_id | +--------+---------+ |1 | 2 | +--------+---------+ |1 | 3 | +--------+---------+ |2 | 1 | +--------+---------+ |2 | 3 | +--------+---------+ |3 | 1 | +--------+---------+ [/code] then say you wanted all the players who have played game_id 3 you could do [b]"SELECT 'user_id' FROM 'games_played' WHERE 'game_id' = 3"[/b] or say you wanted all the games a specific player has played for example user 1 [b]"SELECT ''game_id' FROM 'games_played' WHERE 'user_id' = 1"[/b] I'm no expert but this is how i would go about it, hope this helps[/QUOTE] alright cool thanks for the advice! now, how would i go about selecting a game that a certain user has not played? something like SELECT * FROM games WHERE something=1 AND user_has_not_played_this_game i don't know how to write the user_has_not_played_this_game part, any tips? how would i query from an additional table?
  • You can tell what games the user hasn't played simply by seeing what games they have, by definition every game not on their list is unplayed.
  • right, i was asking more about the technical terms of implementing what i now know is called a "subquery" :) looks like i need something like SELECT * FROM games WHERE open=1 AND NOT EXISTS (SELECT * FROM users_games WHERE user='bob' AND game=???) how would i get the ??? - it needs to be the id of the game from 'games' (the outer query) [editline]12th April 2012[/editline] apparently i'd need SELECT * FROM games WHERE open=1 AND NOT EXISTS (SELECT * FROM users_games WHERE user='bob' AND game=games.id) any other advice?
  • SELECT * FROM `games` WHERE `user_id`='$userid' AND `game_id`='$gameid' Then just check whether or not this is returns something, (given the above table) If it does return something, then he has the game. If it doesn't, he doesn't have it. Or do you really want to know exactly which games he has/doesn't have? [editline]12th April 2012[/editline] Also, where $userid and $gameid are variables.
  • [QUOTE=eternalflamez;35540319]SELECT * FROM `games` WHERE `user_id`='$userid' AND `game_id`='$gameid' Then just check whether or not this is returns something, (given the above table) If it does return something, then he has the game. If it doesn't, he doesn't have it. Or do you really want to know exactly which games he has/doesn't have? [editline]12th April 2012[/editline] Also, where $userid and $gameid are variables.[/QUOTE] If you look at nullsquared's SQL what you're saying is totally wrong. (He has it right)
  • [QUOTE=jung3o;35544517]what are you doing[/QUOTE] Hey, stop talking like an ifaux and learn to build something that looks a bit more like a regular sentence.
  • [QUOTE=icantread49;35540038]right, i was asking more about the technical terms of implementing what i now know is called a "subquery" :) looks like i need something like SELECT * FROM games WHERE open=1 AND NOT EXISTS (SELECT * FROM users_games WHERE user='bob' AND game=???) how would i get the ??? - it needs to be the id of the game from 'games' (the outer query) [editline]12th April 2012[/editline] apparently i'd need SELECT * FROM games WHERE open=1 AND NOT EXISTS (SELECT * FROM users_games WHERE user='bob' AND game=games.id) any other advice?[/QUOTE] subqueries are really bad for performance in mysql
  • [QUOTE=Funcoot;35549471]Why don't I see a lot of people on FP using ASP.NET?[/QUOTE] I'd assume it's because most of the members here either have shared hosting or Linux based VPS hosting (or just don't like ASP.NET). That being said, turb used to use it for some of his stuff (AnyHub being one of them)
  • [QUOTE=Funcoot;35549727]Any good windows hosts out there?[/QUOTE] i'd just buy a windows vps from burst.net
  • My VPS which runs windows Server '08 R2 with IIS 7 has a problem with opening the default page The problem is that it directs me to /index instead of index.php Already changed the Default Document to index.php but it still leads me to /index/ [URL]http://butterfieldhotel.com[/URL] site in question
  • Are you affiliated with Brian Butterfield? :v: Also, do you have any redirect rules setup? the server is forcing a redirect to "/index", which doesn't exist. The default document should just specify what to load when "/" is encountered, not to actually perform a redirect.
  • [QUOTE=eternalflamez;35539643]This is a question regarding Ruby: [CODE]@wattedoens.each do |wattedoen| test = wattedoen.naam.downcase! %> test = <%= test %>, <%= wattedoen.naam %> <br/><br/> global test = <%= $test %> <br/><br/> <% if(test == $test) redirect end end[/CODE] Is what I have. For some reason it shows the name of the first object, and then for the second object, there is a value before I downcase it, but no value in the "test" variable after i downcase. Output: test = tussen_2_voertuigen, tussen_2_voertuigen global test = fietser_of_voetganger test = , fietser_of_voetganger global test = fietser_of_voetganger (Words are Dutch and so are some of the variable names, but you get the picture)[/QUOTE] As extra information: I iterate through an array of objects, then take the name, downcase it, and as test output the name before and after downcasing. Apparantly after downcasing, only the first name has a value, the others just come back as an empty string, even though they have values BEFORE i downcase. I'd like it if it were to be fixed asap.
  • Why does the <li> tag adds spaces between eachother when they have the css display:inline-block applied on them?
  • [QUOTE=xmariusx;35551921]Why does the <li> tag adds spaces between eachother when they have the css display:inline-block applied on them?[/QUOTE] I had trouble with this in Chrome too. What worked for me is making sure that in the HTML there were no line breaks or spaces between <li> tags, which doesn't look great formatting wise but did fix the issue. For example: <li>blah</li><li>blah2<\li>
  • [QUOTE=TheBigS;35552052]I had trouble with this in Chrome too. What worked for me is making sure that in the HTML there were no line breaks or spaces between <li> tags, which doesn't look great formatting wise but did fix the issue. For example: <li>blah</li><li>blah2<\li>[/QUOTE] Adding to this: it's easy to keep the formatting for editing but still have them without line breaks like this: [php]<?php echo '<li>blah</li>'. '<li>blah2</li>'. '<li>blah3</li>'; ?>[/php]
  • TheDecryptor took a look at my VPS and could not find a solution. Any other suggestions? (Forgot to mention, this happened after the install of ColdFusion 9)
  • [QUOTE=Dragory;35552133]Adding to this: it's easy to keep the formatting for editing but still have them without line breaks like this: [php]<?php echo '<li>blah</li>'. '<li>blah2</li>'. '<li>blah3</li>'; ?>[/php][/QUOTE] So I would use PHP to make them without line breaks and still keep them organized in the code? Fair enough.. still strange :P Thanks both of you.
  • [QUOTE=eternalflamez;35551803]As extra information: I iterate through an array of objects, then take the name, downcase it, and as test output the name before and after downcasing. Apparantly after downcasing, only the first name has a value, the others just come back as an empty string, even though they have values BEFORE i downcase. I'd like it if it were to be fixed asap.[/QUOTE] your code is not very easy to understand what are you trying to achieve?
  • [QUOTE=swift and shift;35552753]your code is not very easy to understand what are you trying to achieve?[/QUOTE] Basically I had an array of objects. (@wattedoens) Each object has a variable called "Naam". I put the wattedoen.naam in a variable called "test". Then put that to lower case, so i could compare it with another variable which was also downcased. Yet, only for the first object, the downcased variable called "test" had a value. For the others it was an empty string, even though the string had a value before downcasing. Anyway I fixed it myself: [CODE] <% @wattedoens.each do |wattedoen| test = wattedoen.naam.downcase if(test == $test) redirect :action => :show, :id => wattedoen.object end end %> [/CODE] Basically it was removing the ! at the end of "wattedoen.naam.downcase". Can you explain what the "!" was for then? I googled downcasing, and just used the function in the same way as they did it.
  • isn't it best practise to write all code with english variable names (where possible)?
  • [QUOTE=eternalflamez;35552835]Basically I had an array of objects. (@wattedoens) Each object has a variable called "Naam". I put the wattedoen.naam in a variable called "test". Then put that to lower case, so i could compare it with another variable which was also downcased. Yet, only for the first object, the downcased variable called "test" had a value. For the others it was an empty string, even though the string had a value before downcasing. Anyway I fixed it myself: [CODE] <% @wattedoens.each do |wattedoen| test = wattedoen.naam.downcase if(test == $test) redirect :action => :show, :id => wattedoen.object end end %> [/CODE] Basically it was removing the ! at the end of "wattedoen.naam.downcase". Can you explain what the "!" was for then? I googled downcasing, and just used the function in the same way as they did it.[/QUOTE] #downcase converts the string to lower case and returns it as a new string, #downcase! converts the string to lowercase in place. if the string is already lowercased, it returns nil. also wtf why are you using a global variable
  • True. But this is an app for insurances and I don't know how to translate most of the variable names, and I probably won't ever have to use the words in English again after this. And it has to be maintained (not the program itself, more like, the content, texts etc) by 2 people who don't understand Ruby so it's easier to have it in Dutch to make easier waypoints for them.
  • also don't put parens around the condition in if statements [editline]13th April 2012[/editline] also what the actual fuck why are you redirecting from inside a view [editline]13th April 2012[/editline] my lord this code
  • [QUOTE=swift and shift;35552914]#downcase converts the string to lower case and returns it as a new string, #downcase! converts the string to lowercase in place. if the string is already lowercased, it returns nil. also wtf why are you using a global variable[/QUOTE] Because the framework. I don't fully understand it yet, maybe you can solve this for me? If i use this: [CODE] <a href="<%= url_for :action => :changeVar, :id => schadesoorten.object, :name => item %>"> <%= schadesoorten.Naam %> </a> [/CODE] Name ends up to be nil every time. Id gets a value but if i change it to anything else it just flunks. At the other end, I have: [CODE] def changeVar name = @params['name'] id = @params['id'] redirect :controller => :WatTeDoen, :action => :index end [/CODE] Yet every time only @params['id'] gets a value. Maybe I should just pm you for these questions? Otherwise I'm spamming the thread with my Ruby illiteracy.