pugboy Posted July 11, 2008 Share Posted July 11, 2008 Is there a way to determine if a MySQL database contains a certain value? Kind of like checking if a username is being used or not... Quote Link to comment Share on other sites More sharing options...
DarkerAngel Posted July 11, 2008 Share Posted July 11, 2008 I'm sure there is something better but this is close to what I always use <?php $query = "SELECT username FROM users WHERE username = '{USERNAME}'"; $sql = mysql_query($query); if(mysql_num_rows($sql)) { /* User Exists Code */ } else { /* User NOT Exists Code */ } ?> Quote Link to comment Share on other sites More sharing options...
mbeals Posted July 11, 2008 Share Posted July 11, 2008 <?php $query = "Select `attribute` from Table where `attribute` = 'value' "; $result = mysql_query($query); if(mysql_num_rows($result)){ value exists }else{ it doesn't } ?> beat me to it....and with near exact code too. There is no boolean query that I'm aware of. Besides, if you think about it, just a yes or a no wouldn't really save anything in terms of speed or efficiency. Quote Link to comment Share on other sites More sharing options...
pugboy Posted July 11, 2008 Author Share Posted July 11, 2008 Ok, thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.