Jump to content


Mysql WHERE help


  • Please log in to reply
1 reply to this topic

#1 Guest_PcGamerz13_*

Guest_PcGamerz13_*
  • Guests

Posted 25 March 2006 - 08:01 AM

How do yoy make it Search 5 fields and only shows Win_Tie_Lose='Win'
$sql5=mysql_query("SELECT * FROM clan_matches WHERE Member_1='$Member_Gamer_Tag' OR Member_2='$Member_Gamer_Tag' OR Member_3='$Member_Gamer_Tag' OR Member_4='$Member_Gamer_Tag' OR Member_5='$Member_Gamer_Tag' AND Win_Tie_Lose='Win'");


#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 25 March 2006 - 09:57 AM

Two ways

1 ) Use "()" to separate OR's from the AND

SELECT * FROM clan_matches
      WHERE ((Member_1='$Member_Gamer_Tag')
      OR (Member_2='$Member_Gamer_Tag')
      OR (Member_3='$Member_Gamer_Tag')
      OR (Member_4='$Member_Gamer_Tag')
      OR (Member_5='$Member_Gamer_Tag'))
      AND Win_Tie_Lose='Win'

2 ) Use "IN(list)" instead of the OR's

SELECT * FROM clan_matches
      WHERE '$Member_Gamer_Tag' IN (Member_1, Member_2,Member_3, Member_4,Member_5)
      AND Win_Tie_Lose='Win'

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users