SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2002
    Location
    UK
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help needed: Conditional logic to display a 'No Image' icon

    Hi all,

    I've run into a problem that is giving me a bit of a headache. I'm prety new to PHP, but this problem is probably pretty simple to solve.

    I'm using DWMX 2004, and parts of my site give the option to upload an image. What I need is a simple way to check to see if the db field is empty and if so display a standard 'No Image' file stored on the server, if not, then display the actual image.

    So I was thinking along the lines of a simple script like the following:

    Code:
     
    <?php
    if ($row_rsTest['filename']==' ') {
    <img src="$row_rsTest['filename'];" />
    } else {
    <img src="gfx/cog.gif" />
    }
    ?>
    Obvioulsy this is giving me an error but I can't put my finger on the error (as I said, I suck at PHP coding. )

    Any help would be MUCH appreciated.

    Regards

    Psmeg

  2. #2
    PHP manual bot bronze trophy Gaheris's Avatar
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,195
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Given only this very small piece of code I would guess that this would work
    PHP Code:
    <?php
    if (!empty($row_rsTest['filename'])) {
        echo 
    '<img src="',$row_rsTest['filename'],'" />';
    } else {
        echo 
    '<img src="gfx/cog.gif" />';
    }
    ?>

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2002
    Location
    UK
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Lovely, worked like a charm..

    Cheers

    Psmeg


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
  •