Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Problem with "if" statement in Dreamweaver

New Here ,
Apr 01, 2010 Apr 01, 2010

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.

TOPICS
Server side applications

Views

1.2K
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 01, 2010 Apr 01, 2010

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?

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 02, 2010 Apr 02, 2010

Copy link to clipboard

Copied

LATEST

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?

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines