Simple MySQL Query Problem

Discussion in 'PHP' started by Riverofrhyme, Jun 28, 2008.

  1. #1
    Basically I want to run a query that selects everything from the table 'base_items_cp', but only if the row 'cd' is equal to the variable $ccd . The row 'type' must also be equal to either 'weapon', 'armour', 'boots', 'gloves' or 'helmet'.

    Here was my test query:

    SELECT * FROM base_items_cp WHERE cd='$ccd' AND type='helmet' OR type='gloves' OR type='boots' OR type='armour' OR type='weapon'
    PHP:
    But that took rows regardless of the type, anyone know how to fix this?
     
    Riverofrhyme, Jun 28, 2008 IP
  2. Randombase

    Randombase Peon

    Messages:
    224
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I had to test this to see if it would work, and apparently you need to place the OR clause between brackets, like this:

    SELECT * FROM base_items_cp WHERE (type='helmet' OR type='gloves' OR type='boots' OR type='armour' OR type='weapon') AND cd='$ccd'
    PHP:
     
    Randombase, Jun 28, 2008 IP
  3. Riverofrhyme

    Riverofrhyme Peon

    Messages:
    137
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks a lot, I'll try it out. I actually thought of that, but that was my stupid Math brain coming into place XD .

    EDIT: Yep it worked, thanks.
     
    Riverofrhyme, Jun 28, 2008 IP