Page 1 of 1

PHP and frames

Posted: Thu Oct 16, 2003 8:51 am
by LonelyProgrammer
Hi all,

How does one go about writing frames with PHP? Say I have a frameset which consists of two pages -index.php and mainframe.php, and the frameset document itself (frameset.php). Say I have a form on index.php, or an url there, when click, will affect mainframe.php. How do I go about achieving that?

Second thing, how I can control the output of both index.php and mainbody.php through a form or something?

Posted: Thu Oct 16, 2003 9:09 am
by brewmiser
I am using frames in the current project that I am working on. I have 3 framed windows:

header.php
menu.php
main.php

I also have index.php which set's up each frame. Here is the index.html:

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
  <link rel="stylesheet" type="text/css" href="style.css" />
  <title>Title</title>
</head>
  <frameset rows="85,*" border="0" frameborder="0" framespacing="0">
	  <frame src="header.php" name="header" scrolling="no" noresize marginwidth="0" marginheight="0">
		<frameset cols="135,*" border="0" frameborder="0" framespacing="0">
			<frame src="menu.php" name="menu" scrolling="no" noresize marginwidth="2" marginheight="2">
			<frame src="http://some/url.php" name="main" id="main" scrolling="auto" noresize marginwidth="5" marginheight="5">
		</frameset>
	</frameset>
</html>
If you notice there is no body in the index.html. You do not need it here. Each framed page will only have the <body>, with no <html> or <head> tag.

Then if I need to call a frame in another frame I use the "target= ", like the following:

Code: Select all

<a class="subMenu" href="http://some/url/file.php" target="main">
You change the "target=" to the name of the frame.

Hope this helps, and/or answers your question. :)

Posted: Thu Oct 16, 2003 9:29 am
by m3rajk
umm.. why have them in seperat files like in html???? is there a need?

Code: Select all

<?php
include('pagefuncs.php');

if(isset($_GET['fn'])){ # we know what the frame is
   if($_GET['fn']=='main'){ # we want the main page
     /* code to use to ready mainpage */
     /* page begining functions that are static */
     /* main page content that's dynamic */
     /* close page functions that are static */
   }elseif($_GET['fn']=='?'{ #whatever 
     /* code to use to ready page */
     /* page begining functions that are static */
     /* main page content that's dynamic */
     /* close page functions that are static */
   }
}else{ # we know we're making the frames
   /* anything neededin dynamically creating the frameset */
   /* page beginning that's just the head section */
   /* frame set stuff */
   /* closing for frames */
}
?>
this does three things:

1: it causes modularity (reusable begining and closing functions)
2: it makes for easier upkeep (changing the background color is now just one place... little things like that)


if you make the frames in one and then each page has it's own file, then why use php for the frames? it's not utelyzing any of the ability to be dynamic.

the outline i have set up allows you to utelyze php's on the fly to a much greater degree

Posted: Thu Oct 16, 2003 10:08 am
by brewmiser
m3rajk, I did not know that you could do this. It looks really cool and something that I can use, but can you explain more on how your php works. I do not quite understand.

I only knew that you could do this in HTML, and making it dynamic seems to be the best way to go....sweet.

Thanks.