Copy link to clipboard
Copied
I have successfully used "if" statements in the past with Dreamweaver, but I'm having a problem using it with images (i.e. <img src = ).
What I'm trying to accomplish is to display a default.jpg image if there is no image file name stored in a MySQL database.
For example, if a team has a photo image, show that photo; otherwise, show a default image. (The default image tells people how to submit a photo to me.)
If I can't get this to work, I'll have to store a large number of image files with different names for the same "default.jpg" image.
Thanks in advance for any help that you can provide.
Copy link to clipboard
Copied
Are you trying to accomplish this with a server side script? Whenever you are having problems with code, you need to post the code. Otherwise how can we help?
Copy link to clipboard
Copied
I may have misunderstood your problem... why can't you just set the default value of the column in the table to the path of your default image? Then, when you call that variable into the page, if there has been one set, it will display that, if not, it will display the default.
If there is some reason that you can't do that (if I'm missing your point), this should accomplish the same thing (though, I still think that the easiest way is to simply store the default image URL in the table by default.)
Set the DEFAULT value of the column in the database to "-1" - so if there is nothing there, it returns "-1". Then put the following in the page:
<?php IF ($row_test['team_pic']=="-1")
$image1=('<img src="images/default_pic.jpg">');
ELSE $image1=('<img src="'.$row_test['team_pic'].'">');
?>
<?php echo $image1; ?>
Where your database column is "team_pic", and your default image is "default_pic.jpg" stored in the /images folder.
Make sense?