How to check whether SELECT EXISTS returns a value or not?

后端 未结 7 1459
后悔当初
后悔当初 2021-01-03 19:38

I am trying to quickly determine if a user_ID is the owner of a \'goal\'. I believe my SQL query is good, but I\'m trying to find a nice way of checking the result!

相关标签:
7条回答
  • 2021-01-03 20:11

    I like gbn's answer the best, but I wanted to point out that this:

    if (@mysql_num_rows(mysql_query($query))!=1) {
         return false;
    } else {
         return true;
    }
    

    can be simplified to:

    return @mysql_num_rows(mysql_query($query)) == 1;
    
    0 讨论(0)
提交回复
热议问题