Search code examples
phpconditional-operatorlanguage-construct

if statement on one line if poss


I am printing an image using an ID which is generated. however i wanted to do a check to see if this image exists and if it doesnt print no-image.jpg instead...

<img src="phpThumb/phpThumb.php?src=../public/images/'.$row["id"].'/th.jpg&w=162" alt="" width="162" /> 

It would be great if this could be kept on one line is possible. Any help would be appreciated.


Solution

  • What Kristopher Ives says, and file_exists:

    echo (file_exists("/path/file/name/here") ? "web/path/goes/here" : "no_image.jpg")
    

    btw, your snippet is unlikely to work, as you seem to be combining plain HTML output and PHP without putting the PHP into <? ?>