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... Link to comment https://forums.phpfreaks.com/topic/114343-solved-if-sql-value-exists/ 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 */ } ?> Link to comment https://forums.phpfreaks.com/topic/114343-solved-if-sql-value-exists/#findComment-588003 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. Link to comment https://forums.phpfreaks.com/topic/114343-solved-if-sql-value-exists/#findComment-588005 Share on other sites More sharing options...
pugboy Posted July 11, 2008 Author Share Posted July 11, 2008 Ok, thanks Link to comment https://forums.phpfreaks.com/topic/114343-solved-if-sql-value-exists/#findComment-588051 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.