hellonoko Posted March 27, 2009 Share Posted March 27, 2009 I have below simple query that compares a URL to a list of URLS in a DB. If the imput is found... $rows = 1; Then the code evaluates correctly. However if the imput is not found mysql_num_rows(); returns nothing. Not 0 rows. Not NULL and my 'else' statement fails. So I can only seem to evaluate to TRUE not to FALSE but I need both. How do I do this properly so I can evaluate both ways? $query = mysql_query("SELECT * FROM `secondarylinks` WHERE `link` = '$last_url' && `scraped` = '0' LIMIT 1") or die(mysql_error()); $rows = mysql_num_rows($query) or die(mysql_error()); if ( $rows === 1 ) { echo 'found row'; } else { echo 'not found'; } Quote Link to comment https://forums.phpfreaks.com/topic/151359-solved-properly-evaluating-mysql_num_rows/ Share on other sites More sharing options...
JonnoTheDev Posted March 27, 2009 Share Posted March 27, 2009 $rows = mysql_num_rows($query); $rows = ($rows) ? 1 : 0; Quote Link to comment https://forums.phpfreaks.com/topic/151359-solved-properly-evaluating-mysql_num_rows/#findComment-794997 Share on other sites More sharing options...
hellonoko Posted March 27, 2009 Author Share Posted March 27, 2009 That... Is awesome what does it all mean? Quote Link to comment https://forums.phpfreaks.com/topic/151359-solved-properly-evaluating-mysql_num_rows/#findComment-794999 Share on other sites More sharing options...
hellonoko Posted March 27, 2009 Author Share Posted March 27, 2009 Alright I see how that works but it doesn't. Because its not going to evaluate period because mysql_num_rows(); isn't returning. Period. Quote Link to comment https://forums.phpfreaks.com/topic/151359-solved-properly-evaluating-mysql_num_rows/#findComment-795004 Share on other sites More sharing options...
Mark Baker Posted March 27, 2009 Share Posted March 27, 2009 Try if ( $rows == 1 ) Quote Link to comment https://forums.phpfreaks.com/topic/151359-solved-properly-evaluating-mysql_num_rows/#findComment-795006 Share on other sites More sharing options...
hellonoko Posted March 27, 2009 Author Share Posted March 27, 2009 Works with: if (mysql_num_rows(mysql_query("SELECT * FROM `secondarylinks` WHERE link = '$last_url' && `scraped` = '0' LIMIT 1")) == 1) { Quote Link to comment https://forums.phpfreaks.com/topic/151359-solved-properly-evaluating-mysql_num_rows/#findComment-795008 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.