If statement doesn't seem to work

my if statement seems to be screwed up

	if(isset($row['thumb'])) {
	echo "<img src='../providers/".$row['id']."/thumbs/".$row['thumb']."' class='thumb'>";
} else {
	echo "<img src='../providers/noicon.png' class='thumb'>";
}

but as you can see, the field is empty.


but it produces

<img src="../providers/2/thumbs/" class="thumb">

Am I using isset wrong?

$row[‘thumb’] might be set to an empty string for which isset will return true. Try:

if (isset($row['thumb']) && $row['thumb']) { ...

http://php.net/manual/en/function.isset.php

You might check for empty and also that image exists.

$image_path = '../providers/'.$row['id'].'/thumbs/'.$row['thumb'];
if(!empty($row['thumb']) && file_exists($image_path)){
    echo '<img src="'.$image_path.'" class="thumb">'."\r";
}else{
    echo '<img src="../providers/noicon.png" class="thumb">'."\r";
}

thanks

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.