0

I want to get all the rows that were "given by" the "System"(should only return one row, cause only one row in the table meets that condition). But even tho it gets the row right, and givenBy's value is "System", it still returns "3" in the ternary operator.

So, I have this little piece of code, where $query = mysql_fetch_assoc(mysql_query('SELECT * FROM regtokens WHERE token = \'' . $token . '\''));

Here is my Code :

echo $query['givenBy'];  //outputs "System"

$level = ($query['givenBy'] === 'System' ? 1 : 3);  

echo $level;             //outputs "3"

How can i do this ?

Balaji Kandasamy
  • 4,446
  • 10
  • 40
  • 58
P3t3r6
  • 1,398
  • 2
  • 9
  • 12

1 Answers1

0

It seems that you have to use trim to remove empty spaces. i also prefer to use strtolower to comparing this type of strings.

you can try like this:

$level = (trim(strtolower($query['givenBy'])) === 'system' ? 1 : 3);  

echo $level;
Awlad Liton
  • 9,366
  • 2
  • 27
  • 53