Page 1 of 1
Dynamic content
Posted: Thu Oct 16, 2003 6:35 pm
by chriso
Is it possible to display an html or php page through another php/html document? For example, lets say I have a php page called index.php. In this page I have a table:
Code: Select all
<table>
<tr>
<td>echo $content;
</tr>
</table>
Now, if a person clicks on link A, then $content = page1.html and the page1.html document is displayed in the table.
However, if a person clicks on link B, then $content = page2.php?key=value and that page and it's processed results are displayed in the table.
If I can do this, could someone write me the code for a simple example of how I would do this?
Thank you.
Posted: Thu Oct 16, 2003 7:07 pm
by Gen-ik
Page One...
Code: Select all
<body>
<table>
<tr>
<td><? require("page2.php?anyVar=anyValue") ?></td>
</tr>
</table>
</body>
Page Two (page2.php)...
Code: Select all
anything you want to appear in the td.<br>
<? echo("php also get run before it's include in the td") ?><br>
The value of anyVar is <? echo($_GET["anyVar"] ?><br><br>
Hope that helps!
Posted: Thu Oct 16, 2003 7:12 pm
by McGruff
You can define GET vars in the link, and then the script that defines $content can create different content according to the GET vars it receives.
For example:
<a href="index.php?page=articles&aid=12"></a>
..defines two elements in the $_GET superglobal array: $_GET['page'] and $_GET['aid'].
This would tell a script that the user has selected an article with article id = 12.
otherwise
Posted: Thu Oct 16, 2003 7:18 pm
by loco_ola
if you dont want to pass variables and have it all in one page you cuold do it like this:
Code: Select all
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<META http-equiv="Content-Style-Type" content="text/css">
<script>
function WriteIt(id,nestref,text) {
if(document.all) {
document.all('thisdiv').innerHTML = text;
}
else if (document.getElementById) {
document.getElementById('thisdiv').innerHTML=text;
}
else if (document.layers) {
document.layers('thisdiv').innerHTML = Text;
}
}
</script>
<TITLE></TITLE>
</head>
<body bgcolor="#ffffff">
<TABLE BORDER=1>
<TR>
<TD width="128">
<!--write what you want in the bit "<strong>change your stuff here.</strong>" in the link. -->
<a href="javascript:WriteIt('thisdiv',null,'<strong>change your stuff here.</strong>')">First Button </a><br>
<a href="javascript:WriteIt('thisdiv',null,'whatever else.')">Second Button </a></TD>
<TD width="196">
<div id="thisdiv" style="position:relative;">
<table>
<tr>
<td>
Whatever.....</td>
</tr>
</table>
</div>
</TD>
</TR>
</TABLE>
<BR>
</body>
</html>
but this is not really worth doing if you can do it how the others suggested as its pretty clunky but does save you changing pages if you were trying to avoid that. you could make it dynamic too but dont forget you are loading unnecessary data.
Example
Posted: Thu Oct 16, 2003 7:19 pm
by markl999
My 2 cents
Code: Select all
<a href="/index.php?id=1">Link A</a>
<a href="/index.php?id=2">Link B</a>
<a href="/index.php?id=3">Link C</a>
etc..and in index.php do ...
Code: Select all
<?php
if(!isset($_GET['id'])){
$_GET['id'] = 1; //sets a default page to display
}
if(!file_exists('page'.$_GET['id'].'.html')){
$_GET['id'] = 1; //makes sure they don't ask for page456 etc..
}
?>
<table>
<tr>
<td><?php require_once 'page'.$_GET['id'].'.html' ?></td>
</tr>
</table>
If your pages arn't all named page1.html page2.html etc.. then you'de just add an extra GET var as McGruff illustrated. Course i've skipped error checking and other essentials but it should provide an idea and you should be able to modify it to handle php files, different files in different directories etc..