galvin Posted March 17, 2011 Share Posted March 17, 2011 Probably a silly question, but say you have a value in a mysql database that (naturally) can be either be blank or have characters in it. If in my PHP I am doing a check to see if that returned field from the database HAS or DOES NOT HAVE a value entered in it, what is the proper way to do it? For example, you could do either of the following below (and I'm sure there are probably 10 other ways to do it as well). Is one of these quicker/more efficient than the other? I know it probably does not matter in the grand scheme of things because it's such a quick check either way, but if one way is more "proper" than the other, please let me know... if ($mysqlvalue!=="") OR if (strlen($mysqlvalue>0)) OR Quote Link to comment Share on other sites More sharing options...
nicholasolsen Posted March 17, 2011 Share Posted March 17, 2011 if (isset($value)) { // value is set } else if (empty($value)) { // value is not set } Hope it helps :-) Quote Link to comment Share on other sites More sharing options...
phpTrainee Posted March 17, 2011 Share Posted March 17, 2011 This checks for 0s, null, false, empty arrays, empty strings, empty variables. if (empty($mysqlvalue)) { } 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.