PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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:
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!
<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.
<?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..