1

Hello Stackers

I'm having another Question, this time about the deprecated MySQL. I'm having the following Query

mysql_query("SELECT * FROM cms_notificaties WHERE username = '". $user['id'] ."' AND userstatus = 'unseen' OR userstatus = 'priority' ")or die(mysql_error());

This will select all notifictions, even when the WHERE username value isn't correct. However, I Want that only the notifications with the right user id will be requested, but, only the ones with the userstatus unseen OR priority. How can I do that? Is that even possible with MySQL?

A Small sidenote, I Know that MySQL is deprecated, but I need to change the whole CMS for that, which I will do later in time.

Pascal Boschma
  • 187
  • 1
  • 14

2 Answers2

2

Take a look at this link where it says that OR has lower operator precedence than AND. So you need to use parentheses, something like this:

SELECT * FROM cms_notificaties WHERE username = '". $user['id'] ."' AND ( userstatus = 'unseen' OR userstatus = 'priority' )
Community
  • 1
  • 1
eol
  • 23,236
  • 5
  • 46
  • 64
1

Use bracket around OR condition.

SELECT * FROM cms_notificaties WHERE username = '". $user['id'] ."' AND ( userstatus = 'unseen' OR userstatus = 'priority' )
Deval Shah
  • 1,094
  • 8
  • 22