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
https://forums.phpfreaks.com/topic/7728-sql-or-statement/
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
https://forums.phpfreaks.com/topic/7728-sql-or-statement/#findComment-28243
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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