Scooby08 Posted June 6, 2012 Share Posted June 6, 2012 I'm just looking for an opinion on a recommended way to search a database for a specific value.. Would it be one of the following or perhaps there is a better approach?? <?php $count = mysql_result(mysql_query("SELECT count(*) FROM bank_routing_numbers WHERE blacklist='091000019'"),0); if ($count > 0) { // exists } else { // doesnt exist } ?> or <?php $num_rows = mysql_num_rows(mysql_query("SELECT blacklist FROM bank_routing_numbers WHERE blacklist='091000019'")); if ($num_rows > 0) { // exists } else { // doesnt exist } ?> Quote Link to comment Share on other sites More sharing options...
Illusion Posted June 7, 2012 Share Posted June 7, 2012 See it for yourself by run the queries using EXPLAIN from any sql client. Quote Link to comment Share on other sites More sharing options...
fenway Posted June 16, 2012 Share Posted June 16, 2012 There could be thousands of matching rows -- don't get data just to throw it out. 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.