Jump to content

Checking Null results MySQL


williamZanelli

Recommended Posts

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

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

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.";

}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.