Jump to content


Photo

SQL OR statement


  • Please log in to reply
2 replies to this topic

#1 Canman2005

Canman2005
  • Members
  • PipPipPip
  • Advanced Member
  • 669 posts

Posted 18 April 2006 - 03:15 PM

Dear all

I have this sql statement

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

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

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

but it didnt seem to like that

Any ideas?

Thanks in advance

Ed

#2 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 18 April 2006 - 03:55 PM

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
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#3 Roberto

Roberto
  • Members
  • PipPip
  • Member
  • 16 posts
  • LocationLondon, England

Posted 18 April 2006 - 05:17 PM

[!--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) View Post[/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

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

Note the OR and the ()

Rob
*************************************
Mad Mouse Media Web Design
t: (+34) 610 837 558
e: rob@madmousemedia.co.uk
w: www.madmousemedia.co.uk
w: www.madmouseart.com *************************************




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users