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 Link to comment https://forums.phpfreaks.com/topic/230876-checking-to-see-if-a-value-returned-from-the-database-is-blank-or-not/ 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 :-) Link to comment https://forums.phpfreaks.com/topic/230876-checking-to-see-if-a-value-returned-from-the-database-is-blank-or-not/#findComment-1188495 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)) { } Link to comment https://forums.phpfreaks.com/topic/230876-checking-to-see-if-a-value-returned-from-the-database-is-blank-or-not/#findComment-1188498 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.