The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

image displayed unless value null

I have a page that, depending on the value of id (which is passed on from the previous page, the contents of that particular record of a databse is displayed on the page. I need to put images in only SOME of the records...or rather, the url to the images. How would I script an expression that will display an image (according to the dynamic url) if there is a value in the image_url field, and display nothing (including a broken image link) if the value is null. Obviously, I'm using PHP.

Hmm, tough one and I am not sure if the following does what you want it to do, also, "including a broken image link", I have no idea how to do that and I am not even sure if that will work, I don't think PHP is capable of checking if the file excists..

Anyway, to display an image ONLY when an ID is entered in the string in the URL you can easily use an If statement..

I have an id that is passed from a link on one page. That id ranges from 1-16. On this PHP page that I am editing, I have a script that I have been using that takes the contents of the db and populates an array. So I am wanting to go back now and add a field called image_url to the db. Some records will have a value for image_url, some won't.

What I want is for the PHP page to display the image url that is created from the value "image_url". If the value is null, I don't want anything displayed. When I referred to broken links I meant that some browsers are set to display a placeholder/ or a broken image placeholder if the image is non-existent or loading. I don't want either of those. In fact, I don't want the server to return anything about an image if the value for "image_url" is null.

Well, you know what that IF statement does? (Just to make it more clear)

PHP Code:

<?

if ($image_url != "") {

[ Display imagecode and URL retrieving-code here ]

}
?>

I assume there was an image_url variable in the URL, so it checks for it and whenever it is NOT equal to "" (nothing) then it outputs the code in the IF. I use this IF-statement very much and it always work well