Jump to content

[SOLVED] I'm stuck with if/else :-(


willdk

Recommended Posts

Ok...I have a folder with images that I use in a page. BUT sometimes there is a broken link, because the image doesn't exist. SO I made t-blank.gif for the broken links.

 

My code is not working...and I don't understand why ???

 

<img src="http://localhost/test/thumbs/t-<?php
if (empty($url)) {
echo 'blank';
} else {
echo $url;
}
?>.gif" border="0">

 

I get the last 'echo url' as result, and the 'echo blank' is not used when there is an error (it doesn't exist).

Link to comment
Share on other sites

@KingPhilip

No luck with your code. I still get empty spots for non-existing images.

 

Because I know the path of the non-existing image, it must be someting with checking that path and then let the script show blank.gif or not. I tried something in this direction but no luck yet...

 

$checurl = "http://localhost/test/thumbs/t-".$url.".gif"
...
if (empty($checurl)) {
echo 'blank';
} else {
...

Link to comment
Share on other sites

<img src="http://localhost/test/thumbs/t-<?php
if(!isset($url) || empty($url)) 
echo 'blank';
else
echo $url;
?>.gif" border="0">

 

What does the source show?

 

Look at your browser's source code when you view the page. What do you see?

 

You should see:

<img src="http://localhost/test/thumbs/t-blank.gif" border="0">

 

That's what I see when I run the code. I'm thinking maybe your wanting to check to see if the file exists, and not if the variable is empty?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.