Jump to content

Archived

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

Canman2005

SQL OR statement

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

Share this post


Link to post
Share on other sites
try this:
$sql = "SELECT * FROM members WHERE year = '$year' AND membership_no = 0 AND membership_no = '".$_SESSION['MEMIDD']."'";

just basicaly put $_SESSION['memidd'] inside ' ' in the query as well as $year :)


Regards
Liam

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

×

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.