Simple question

Discussion in 'PHP' started by knightrider, Sep 14, 2007.

  1. #1
    How do I display a html page based on a varibale:

    if ($q = 1)
    call "a1.html"
    else
    call "a2.html"

    I´m freshman in PHP but no in software development!:D
     
    knightrider, Sep 14, 2007 IP
  2. tamen

    tamen Peon

    Messages:
    182
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    include("file.html");
     
    tamen, Sep 14, 2007 IP
  3. jakomo

    jakomo Well-Known Member

    Messages:
    4,262
    Likes Received:
    82
    Best Answers:
    0
    Trophy Points:
    138
    #3
    Hello,
    yes you can use include or requiere :)

    Besdt,
    jakomo
     
    jakomo, Sep 15, 2007 IP
  4. azoundria

    azoundria Member

    Messages:
    38
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #4
    Here's something a bit more complete:

    <?php
     switch($q) {
      case 1:
       $filename = "a1.htm";
      break;
      case 2:
       $filename = "a2.htm";
      break;
      case 3:
       $filename = "products.htm";
      break;
     }
    
     include "header.htm";
     include $filename;
     include "footer.htm";
    ?>
    PHP:
     
    azoundria, Sep 15, 2007 IP
  5. HypertextFever

    HypertextFever Peon

    Messages:
    158
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    so:

    
    if ($q = 1){
      include("a1.html");
    } else {
      include("a2.html");
    }
    
    PHP:
     
    HypertextFever, Sep 16, 2007 IP
  6. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Almost.

    You actually want:
    
    if ($q == 1){
      include("a1.html");
    } else {
      include("a2.html");
    }
    
    PHP:
    Notice the double equal sign in the first line.
     
    TwistMyArm, Sep 16, 2007 IP
  7. HypertextFever

    HypertextFever Peon

    Messages:
    158
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Doh, I missed that :)

    Thanks Twist.
     
    HypertextFever, Sep 16, 2007 IP
  8. tamen

    tamen Peon

    Messages:
    182
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #8
    He, I missed that too many times too. Get used to it. Every once in a while you do it and use up half an hour figuring out why your script seems to be doing something that's not supposed to be doable.

    That, and forgetting what argument goes where in a strpos.
     
    tamen, Sep 16, 2007 IP