Using PHP to load part of a page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • csubillr
    New Member
    • May 2007
    • 17

    Using PHP to load part of a page

    I want to use PHP to select a file in one HTML DIV and load it in a second DIV on the same page. Then select a second file from the first division for reloading the second DIV.

    First, is this possible using PHP?

    Second, as a total PHP novice, here is all I have so far, and I know I am missing something.

    <?php
    if ($_GET["page"] == "home")
    include("home.p hp");
    else if ($_GET["page"] == "info")
    include("info.p hp");
    ?>

    How do I display my choices (home and info) on the page? Do I use a list?

    Once I make a selection, how do I display what I have selected?

    Bill
  • JMathews
    New Member
    • Apr 2007
    • 10

    #2
    Yes you can do this in PhP :)

    What you would have to do is make a <form> for the selection and set the "Page" variable using it. Then use the submit button to pass the variable. You could also do this with an active Java control.

    Since PhP does it's work before the page is rendered, you would have to refresh the page to get the desired content out as the first pass would give the possible choices.

    so let me see about some code here :) this is w/o using any javascript as I avoid it like the plague personally. This would be an example of what you would do to render the selection menu.

    Code:
    <form action = "page.php" method="get">
    <input type="radio" name="page" value="page1" checked="checked" >
    <input type="radio" name="page" value="page2" >
    <input type="submit" value="submit">
    </form>
    this would be some PhP for the selection

    Code:
    <?php
    
    if ($_GET['page'] == "page1")
    {
    include("page1.php");
    }
    else
    {
    include ("page2.php");
    }
    
    ?>
    mind you there are a pile of ways to do this, it really comes to personal choice.

    Comment

    • Motoma
      Recognized Expert Specialist
      • Jan 2007
      • 3236

      #3
      Originally posted by csubillr
      I want to use PHP to select a file in one HTML DIV and load it in a second DIV on the same page. Then select a second file from the first division for reloading the second DIV.

      First, is this possible using PHP?

      Second, as a total PHP novice, here is all I have so far, and I know I am missing something.

      <?php
      if ($_GET["page"] == "home")
      include("home.p hp");
      else if ($_GET["page"] == "info")
      include("info.p hp");
      ?>

      How do I display my choices (home and info) on the page? Do I use a list?

      Once I make a selection, how do I display what I have selected?

      Bill
      What you are looking to do is something that is better done in Javascript, unless you want to reload the entire page each time you change the content of a div.

      Comment

      • csubillr
        New Member
        • May 2007
        • 17

        #4
        Originally posted by JMathews
        Yes you can do this in PhP :)

        What you would have to do is make a <form> for the selection and set the "Page" variable using it. Then use the submit button to pass the variable. You could also do this with an active Java control.

        Since PhP does it's work before the page is rendered, you would have to refresh the page to get the desired content out as the first pass would give the possible choices.

        so let me see about some code here :) this is w/o using any javascript as I avoid it like the plague personally. This would be an example of what you would do to render the selection menu.

        Code:
        <form action = "page.php" method="get">
        <input type="radio" name="page" value="page1" checked="checked" >
        <input type="radio" name="page" value="page2" >
        <input type="submit" value="submit">
        </form>
        this would be some PhP for the selection

        Code:
        <?php
        
        if ($_GET['page'] == "page1")
        {
        include("page1.php");
        }
        else
        {
        include ("page2.php");
        }
        
        ?>
        mind you there are a pile of ways to do this, it really comes to personal choice.
        Thanks. I will play around with this and see how it works for me.

        Comment

        • csubillr
          New Member
          • May 2007
          • 17

          #5
          Originally posted by Motoma
          What you are looking to do is something that is better done in Javascript, unless you want to reload the entire page each time you change the content of a div.
          Thanks. I will play around with the PHP and see if I can learn something and also see how I like it.

          I have never done anything in Javascript except from programs I have downloaded. Guess it is time to learn more.

          Bill

          Comment

          Working...