Jump to content

Query with multiple where clauses


wouterblacquiere

Recommended Posts

Hello,

 

I'm fairly new to php and I'm working on a website for a chess club. I'd like the user to select all of his or her personal results from a general results table.  The results table looks as follows:

 

id        name_white        name_black        result          season_id

 

1          john                    pete                    1-0              2010-2011

2          charles                steve                  0-1              2010-2011

3          richard                john                    1-0              2010-2011

etc

11        isaac                  john                    1-0              2011-2012

12        william                kate                    0-1              2011-2012

13        john                    bobby                  1-0              2011-2012

etc

 

Let us say that the user wants to see all the results of player john in the 2010-2011 season.  The following query (probably quite naively) gives me the error "supplied argument is not a valid MySQL result resource":

 

$result_personal = mysql_query("SELECT * FROM results WHERE name_white = '$seleted_name' AND name_black = '$selected_name' AND season id ='$selected_season'");

 

Could anyone help me steer in the right direction?  Should I use a JOIN query instead?  Or a IN query?

 

All the best and thanks in advance for your time,

 

Wouter.

Link to comment
Share on other sites

Thanks very much for the tip. It worked beautifully!

 

However, I do not understand why it works. You would think that if I want the player's name that can appear in both the white and the black columns, surely I need the AND clause? Why does the OR clause show them both?

 

All the best,

 

Wouter.

Link to comment
Share on other sites

However, I do not understand why it works. You would think that if I want the player's name that can appear in both the white and the black columns, surely I need the AND clause? Why does the OR clause show them both?

 

Because you stated in your original post you wanted to retrieve ALL the records for a player.  If you wanted to only display the results requiring conditionally met circumstances (such as black and white) then AND would be appropriate.

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.