By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,216 Members | 1,032 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,216 IT Pros & Developers. It's quick & easy.

Using PHP to load part of a page

P: 17
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.php");
else if ($_GET["page"] == "info")
include("info.php");
?>

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
May 9 '07 #1
Share this Question
Share on Google+
4 Replies


P: 10
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.

Expand|Select|Wrap|Line Numbers
  1. <form action = "page.php" method="get">
  2. <input type="radio" name="page" value="page1" checked="checked" >
  3. <input type="radio" name="page" value="page2" >
  4. <input type="submit" value="submit">
  5. </form>
  6.  
this would be some PhP for the selection

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. if ($_GET['page'] == "page1")
  4. {
  5. include("page1.php");
  6. }
  7. else
  8. {
  9. include ("page2.php");
  10. }
  11.  
  12. ?>
  13.  
mind you there are a pile of ways to do this, it really comes to personal choice.
May 9 '07 #2

Motoma
Expert 2.5K+
P: 3,235
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.php");
else if ($_GET["page"] == "info")
include("info.php");
?>

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.
May 9 '07 #3

P: 17
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.

Expand|Select|Wrap|Line Numbers
  1. <form action = "page.php" method="get">
  2. <input type="radio" name="page" value="page1" checked="checked" >
  3. <input type="radio" name="page" value="page2" >
  4. <input type="submit" value="submit">
  5. </form>
  6.  
this would be some PhP for the selection

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. if ($_GET['page'] == "page1")
  4. {
  5. include("page1.php");
  6. }
  7. else
  8. {
  9. include ("page2.php");
  10. }
  11.  
  12. ?>
  13.  
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.
May 10 '07 #4

P: 17
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
May 10 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.