David Willis David Willis - 1 year ago 47
SQL Question

How to check if mysql entry is empty in PhP?

here is the description variable I am echoing from my table:

$description = mysql_result($result,$i,"description");

sometimes the $i'th record is empty and doesn't have any data in it/no description.

What I want to do is echo "No description available" for records that are empty

if (isset($description)){ echo "No description available";}
else{ echo $desctipion;}

My attempt doesn't work though as it then echoes No description available for every record even those which aren't empty.

What is the answer?


isset($description) will result true because $description is still set, even though its value is 'empty'. What you need to use is empty.

if (empty($description)) {
    echo "No description available";
} else {
    echo $description;