futrose Posted October 29, 2010 Share Posted October 29, 2010 I have this line in my code $result2 = mysqli_query($link, 'Select * from categories where cat_loc ='.$nav['id']); how do I say "if $result2 is empty or false"? (basically if it didn't find any cat_loc = to $nav['id']) to echo '</li>'; Quote Link to comment https://forums.phpfreaks.com/topic/217170-how-do-i-say-if-variable-is-empty/ Share on other sites More sharing options...
Pikachu2000 Posted October 29, 2010 Share Posted October 29, 2010 Check how many rows are returned with mysqli_num_rows() Quote Link to comment https://forums.phpfreaks.com/topic/217170-how-do-i-say-if-variable-is-empty/#findComment-1127849 Share on other sites More sharing options...
PFMaBiSmAd Posted October 29, 2010 Share Posted October 29, 2010 $result2 will be a result resource if the query executed or it will be a false value if the query failed due to an error. A query that matches zero rows is a successful query. You need to use mysqli_num_rows($result2) to check how many rows are in the result set. Quote Link to comment https://forums.phpfreaks.com/topic/217170-how-do-i-say-if-variable-is-empty/#findComment-1127851 Share on other sites More sharing options...
futrose Posted October 29, 2010 Author Share Posted October 29, 2010 thanks guys, worked like a charm. Quote Link to comment https://forums.phpfreaks.com/topic/217170-how-do-i-say-if-variable-is-empty/#findComment-1127852 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.