Jump to content

SQL OR statement


Canman2005

Recommended Posts

Dear all

I have this sql statement

[code]$sql = "SELECT * FROM members WHERE year = $year AND membership_no =".$_SESSION['MEMIDD'];[/code]

As well as selecting all rows which match the session ID for membership number, I want to pull in all rows which have the membership_no as 0, I tried

[code]$sql = "SELECT * FROM members WHERE year = $year AND membership_no = 0 AND membership_no =".$_SESSION['MEMIDD'];[/code]

but it didnt seem to like that

Any ideas?

Thanks in advance

Ed
Link to comment
Share on other sites

[!--quoteo(post=366057:date=Apr 18 2006, 04:55 PM:name=shocker-z)--][div class=\'quotetop\']QUOTE(shocker-z @ Apr 18 2006, 04:55 PM) [snapback]366057[/snapback][/div][div class=\'quotemain\'][!--quotec--]
try this:
$sql = "SELECT * FROM members WHERE year = '$year' AND membership_no = 0 AND membership_no = '".$_SESSION['MEMIDD']."'";
[/quote]
Surely it should be

[code]
$sql = "SELECT * FROM members WHERE year = '$year' AND (membership_no = 0 OR membership_no = '".$_SESSION['MEMIDD']."')"; [/code]

Note the OR and the ()

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