Jump to content

Need help on how to approach this query, JOIN maybe?


sw0o0sh

Recommended Posts

 

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.

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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");

Link to comment
Share on other sites

[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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.