lurn Posted January 24, 2010 Share Posted January 24, 2010 I have spent a few hours researching this just because I was curious and can't seem to find a good answer. Normally I would do something like the following in PHP: $query = "SELECT subd FROM tblsubd WHERE subd = '" & .$idstr. & "') "; $result = mysql_query($query); $num = mysql_num_rows($result); if ($num != 0){ } The table only has 1 column so I just need to check if exist or not. Seems like there has to be a better way. Wouldn't the way I am doing it continue down the column even if it finds a result and search the whole column? I am trying to avoid that if possible. Thanks in advance so I can continue on. Link to comment https://forums.phpfreaks.com/topic/189595-check-if-exist-better-solution/ Share on other sites More sharing options...
fenway Posted January 28, 2010 Share Posted January 28, 2010 If you're just checking to see if a given unique value exists, use count(*) and check mysql_num_rows(). Link to comment https://forums.phpfreaks.com/topic/189595-check-if-exist-better-solution/#findComment-1002780 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.