SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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.

    Sketch
    Aaron Brazell
    Technosailor



  2. #2
    1-800-JMULDER JMulder's Avatar
    Join Date
    May 2001
    Location
    The Netherlands
    Posts
    1,745
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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..

    PHP Code:
    <?

    if ($image_url != "") {

    Display imagecode and URL retrieving-code here ]

    }
    ?>
    Something tells me this is not what you mean..
    Jeroen Mulder

    w: www.jeroenmulder.com

  3. #3
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no it's not!

    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.

    Does that make more sense?

    Sketch
    Aaron Brazell
    Technosailor



  4. #4
    1-800-JMULDER JMulder's Avatar
    Join Date
    May 2001
    Location
    The Netherlands
    Posts
    1,745
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes it does, but you woul still need to use a similar IF statement I think

    Otherwise, whack me with a stick and let someone else try to understand it
    Jeroen Mulder

    w: www.jeroenmulder.com

  5. #5
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    okay.
    I think I got it now. Thanks.

    Oh, and regardless, I think I'll whack you with a stick!

    Sketch
    Aaron Brazell
    Technosailor



  6. #6
    1-800-JMULDER JMulder's Avatar
    Join Date
    May 2001
    Location
    The Netherlands
    Posts
    1,745
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

    And whack me again if you get more confused now
    Jeroen Mulder

    w: www.jeroenmulder.com


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •