IF Statement question

Discussion in 'PHP' started by kampbell411, May 19, 2008.

  1. #1
    Hi,

    I was wondering if someone could help me with something I am working on. I am trying to have a certain banner show only on a certain search results page. For instance, if the url is mydomain.com/viewtopic.php?f=37 is viewed i would want a certain banner to show just for that specific URL. How would my IF statement have to be in my viewtopic.php page? Thanks!
     
    kampbell411, May 19, 2008 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    If would do it like this:

    
    <?php
    $image = '';
    
    switch((int)$_GET['f'])
    {
    
    case 37:
    
    $image = 'this_image.jpg';
    
    break;
    
    default:
    
    $image = 'that_image.jpg';
    
    }
    
    ?>
    
    PHP:
    Further down you would echo out the image.

    
    
    echo '<img src="images/'.$image.'">';
    
    
    PHP:
     
    jestep, May 19, 2008 IP
  3. samyak

    samyak Active Member

    Messages:
    280
    Likes Received:
    7
    Best Answers:
    4
    Trophy Points:
    90
    #3
    Check the scriptname

    if ($_SERVER['SCRIPT_FILENAME'] == 'viewtopic.php')
    $image = "viewtopic_banner.png";
    else
    $image = "another_banner.png";
     
    samyak, May 19, 2008 IP
  4. kampbell411

    kampbell411 Peon

    Messages:
    82
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Perfect! Thanks for the help.
     
    kampbell411, May 19, 2008 IP