SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Zealot webreadyaudio's Avatar
    Join Date
    Sep 2003
    Location
    Wylie, TX
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need Help With Simple If Statement

    I am pulling data from a DB using php and MySQL, I need to set up a if statement that says:
    if this variable contains data (its text data of a file name) then display this

    Code:
    PHP Code:
    <?php if $row_TourDatesDetail['eflyer']; = "  " { <a href="http://www.site.com/eFlyers/<?php echo $row_TourDatesDetail['eFlyer']; ?>.PDF" target="new"><img src="file.gif"></a>  }else{ No flyer }
    The variable is text, so if there is text in this field record, i need it to show a image with a link to a file, if not, I want it to have nothing show...
    I know its something simple, and I maybe half way there, just stuck on this one...

    thanks,

  2. #2
    SitePoint Member aavf's Avatar
    Join Date
    Nov 2003
    Location
    Trondheim
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    perhaps would work:
    if ($row_TourDatesDetail['eflyer'] != "") { ?>

    if it's not empty, it would have contents right?
    also, it looks like your missing ?> after the {'s

  3. #3
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Another solution is using empty()
    PHP Code:
    if (!empty($row_TourDatesDetail['eflyer'])) {
        echo 
    '<a href=\"http://www.site.com/eFlyers/' ,$row_TourDatesDetail['eFlyer'], 'PDF" target="new"><img src="file.gif"></a>'
    } else {
        
    //No flyer

    Hope this helps

    -Helge

  4. #4
    SitePoint Zealot webreadyaudio's Avatar
    Join Date
    Sep 2003
    Location
    Wylie, TX
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lightbulb

    ok, thanks for you reply's although I still can't get either one to proberly go through the statement...
    here is what I have currently,
    Code:
    PHP Code:
    <?php if ($row_TourDatesDetail['eflyer'] !=" ") {  //No flyer } else {        echo  ('<a href="/eFlyers/'$row_TourDatesDetail['eFlyer'] . '.PDF" target="new">' '<img src="gfx/flyericon.jpg" alt="download flyer" border="0"></a>');  }  ?>
    i either get the icons showing up twice, or it displays the icon on every record, so it's not seeing if that record is null or not...

    thanks for the help, any other ideas???

  5. #5
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Strange. Using empty() should work.
    Based on the code above, how can the picture show up twice? Maybe there's a problem in another part of your code?

    -Helge

  6. #6
    SitePoint Zealot webreadyaudio's Avatar
    Join Date
    Sep 2003
    Location
    Wylie, TX
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    my bad on the the image showing up twice

    but, with this

    Code:
    PHP Code:
    <?php if (!empty($row_TourDatesDetail['eflyer'])) {    echo ('<a href="/eFlyers/'$row_TourDatesDetail['eFlyer'] . '.PDF" target="new">' '<img src="gfx/flyericon.jpg" alt="download flyer" border="0"></a>');  } else {  echo ('no flyer');}?>
    it outputs no flyer only, so it sees every record as empty, which is not the case...??

  7. #7
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hhmmm
    Try
    PHP Code:
    if ($row_TourDatesDetail['eflyer'] != "") { 
    -Helge

  8. #8
    SitePoint Zealot webreadyaudio's Avatar
    Join Date
    Sep 2003
    Location
    Wylie, TX
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yea..does the same thing...I'm at a lost, maybe I should look into convert to bolean...??

    Thanks for the help Hedge!!


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
  •