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
https://forums.phpfreaks.com/topic/145025-solved-im-stuck-with-ifelse/
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 {
...

<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?

When I use your code I get

<img src="http://localhost/test/thumbs/t-image23.gif" border="0"> BUT t-image23.gif doesn't exist.

 

And I think the solution is something with first checking if that image exists and then act. I think I made a mistake by thinking it was something with the var

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.