PDA

View Full Version : MYSQL Select statment Where something equals a or b?


LJackson
08-13-2009, 07:37 PM
Hi All,

i am trying to get this statment to select all records where category = either entertainment, computing, or electronics

here is what ive tried
$itemdata = "SELECT *
FROM category_data
WHERE category = 'Entertainment' OR category ='Computing' OR category = 'Electronics'
AND subcat_id = 'Bestsellers'
AND productNo = '1'
ORDER BY id ASC";

any ideas why this isnt working?

many thanks
Luke

BubikolRamios
08-13-2009, 08:51 PM
WHERE (category = 'Entertainment' OR category ='Computing' OR category = 'Electronics')

LJackson
08-13-2009, 09:19 PM
hi mate

ive tried this
$itemdata = "SELECT *
FROM category_data
WHERE (category = 'Entertainment' OR category ='Computing' OR category = 'Electronics')
AND subcat_id = 'Bestsellers'
AND productNo = '1'
ORDER BY id ASC";

and im getting
Notice: Use of undefined constant mysql_query - assumed 'mysql_query'

any ideas
cheers

LJackson
08-13-2009, 09:34 PM
hi mate its ok got it working now, it wasnt category i wanted but page_category lol

thanks for your help
Luke

Old Pedant
08-13-2009, 09:37 PM
Nothing to do with that line of code.

That line *ONLY* assigns a *STRING* to the $itemdata variable. Nothing to do with any actual query.

N.B.: In place of

WHERE (category = 'Entertainment' OR category ='Computing' OR category = 'Electronics')
...

You could more compactly (and faster, by a tiny bit) use:

WHERE category IN ('Entertainment','Computing','Electronics')
...