sw0o0sh Posted March 31, 2010 Share Posted March 31, 2010 Hi, I am coding a highscores for a game website. Currently, I am working on an "opt out" and "opt in" feature for the highscores. If the user is opted out, their rank does not display, if they are opted in, their rank does. Anyways, the rank experience is stored in a table called "rscd_experience". When the highscores table shows results, it loops through this. When they set whether they want to OPT in or out, it is stored in rscd_players.highscoreopt (as either 0 or 1 value). How would I make this query: $grabSkill = $db->query("SELECT DISTINCT(user),exp_" . $getSkill . " FROM rscd_experience ORDER BY exp_" . $getSkill . " DESC LIMIT " . $db->escape($fixStart) . " , 20"); Detect for rscd_players.highscoreopt ? (And if 1, do not display)? I think I'm going to need some clear cut examples to understand this clause, it seems rather complicated. I don't even know if JOIN is meant for this. Thank you in advance for any help. Quote Link to comment https://forums.phpfreaks.com/topic/197088-need-help-on-how-to-approach-this-query-join-maybe/ Share on other sites More sharing options...
JustLikeIcarus Posted March 31, 2010 Share Posted March 31, 2010 You need to post the layout of your tables so we can see the relationship between them. Do the tables all have a player id field, etc..? Quote Link to comment https://forums.phpfreaks.com/topic/197088-need-help-on-how-to-approach-this-query-join-maybe/#findComment-1034645 Share on other sites More sharing options...
sw0o0sh Posted March 31, 2010 Author Share Posted March 31, 2010 Yes, rscd_experience.user == rscd_players.user I don't know how to more accurately explain the layout. It's all in a database named "rscd". Then there is rscd_experience, rscd_players, for tables. The relationship between them? Quote Link to comment https://forums.phpfreaks.com/topic/197088-need-help-on-how-to-approach-this-query-join-maybe/#findComment-1034650 Share on other sites More sharing options...
JustLikeIcarus Posted March 31, 2010 Share Posted March 31, 2010 You would want something like this. $grabSkill = $db->query("SELECT DISTINCT user, exp_" . $getSkill . " FROM rscd_experience, rscd_players WHERE rscd_experience.user = rscd_players.user AND rscd_players.highscoreopt = 0 ORDER BY exp_" . $getSkill . " DESC LIMIT " . $db->escape($fixStart) . " , 20"); Quote Link to comment https://forums.phpfreaks.com/topic/197088-need-help-on-how-to-approach-this-query-join-maybe/#findComment-1034653 Share on other sites More sharing options...
sw0o0sh Posted April 1, 2010 Author Share Posted April 1, 2010 Oooh, wow, that opens up a whole new world in SQL for me. Thank you Quote Link to comment https://forums.phpfreaks.com/topic/197088-need-help-on-how-to-approach-this-query-join-maybe/#findComment-1035065 Share on other sites More sharing options...
Axeia Posted April 1, 2010 Share Posted April 1, 2010 [Edit] Ignore me, guess you're using some class with the escape method as you're using it in your own example as well. I'd be somewhat amazed if that worked for you. 'escape' isn't a method of the PDO class. (I assume $db = new PDO is somewhere in your code) If you're getting an error about that, use $db->quote instead. Although as stated on the page mentioned above you're probably better off using a prepared statement. Quote Link to comment https://forums.phpfreaks.com/topic/197088-need-help-on-how-to-approach-this-query-join-maybe/#findComment-1035156 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.