williamZanelli Posted June 29, 2008 Share Posted June 29, 2008 Hi there, I new to PHP - I programmed a little using Java and i'm not sure how to check if a VARCHAR [in mySQL] is empty [as in no value] or has some value eg. "Fd3s_9zui" See some of my code below // some DB code returns result, database row call $db_result if( $db_result != "" && $thecount <= 10){ $array_with_result = $db_result['field1']; echo ("result = :" .$array_with_result. "<br/>"); } So in essence what I want to check is if the VARCHAR that is returned, is it empty or not.. How do I do this? Do I use == or = null etc..? thanks in advance. Will Link to comment https://forums.phpfreaks.com/topic/112455-checking-null-results-mysql/ Share on other sites More sharing options...
DarkWater Posted June 29, 2008 Share Posted June 29, 2008 if ($someVariable == '') { } Link to comment https://forums.phpfreaks.com/topic/112455-checking-null-results-mysql/#findComment-577370 Share on other sites More sharing options...
williamZanelli Posted June 29, 2008 Author Share Posted June 29, 2008 /thanks for the reply DarkWater, did you mean? if ($someVar == ""){ } else{ .. Link to comment https://forums.phpfreaks.com/topic/112455-checking-null-results-mysql/#findComment-577373 Share on other sites More sharing options...
DarkWater Posted June 29, 2008 Share Posted June 29, 2008 Sure, if you need an else statement. I thought that was a little obvious though, so I didn't post it before. Link to comment https://forums.phpfreaks.com/topic/112455-checking-null-results-mysql/#findComment-577377 Share on other sites More sharing options...
williamZanelli Posted June 29, 2008 Author Share Posted June 29, 2008 Thanks for the help DarkWater. Link to comment https://forums.phpfreaks.com/topic/112455-checking-null-results-mysql/#findComment-577380 Share on other sites More sharing options...
williamZanelli Posted June 29, 2008 Author Share Posted June 29, 2008 Actually... Theres more... The above will obviosuly tell me if the varible has a value or is blank. How do I know if a row has been returned in the first place. i.e. I dont want to go check a varible if the databse query hasnt returned anything? So the Pseudocode would be like if ($row != null){ if ($someVAr == ""){ }else...... Does this make sense? thanks Will Link to comment https://forums.phpfreaks.com/topic/112455-checking-null-results-mysql/#findComment-577385 Share on other sites More sharing options...
DarkWater Posted June 29, 2008 Share Posted June 29, 2008 if (mysql_num_rows($result) == 0) { while ($row = mysql_fetch_assoc($result)) { if ($row['some_field'] != '') { echo "Hey."; } else { echo "The value is NULL."; } } } else { echo "Query returned blank."; } Link to comment https://forums.phpfreaks.com/topic/112455-checking-null-results-mysql/#findComment-577388 Share on other sites More sharing options...
williamZanelli Posted June 29, 2008 Author Share Posted June 29, 2008 Thanks for the reply DarkWater. Link to comment https://forums.phpfreaks.com/topic/112455-checking-null-results-mysql/#findComment-577424 Share on other sites More sharing options...
DarkWater Posted June 29, 2008 Share Posted June 29, 2008 My bad, it should be: if (mysql_num_rows($result) != 0) { On the first line. Link to comment https://forums.phpfreaks.com/topic/112455-checking-null-results-mysql/#findComment-577426 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.