Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Using Frames with PHP

SHOULD I USE FRAMES? DO THEY WORK WITH PHP?

I'm not a great fan of frames - but they do have their uses. For example, if you wish to select a whole series of items from a hierarchy such as a directory structure, you might choose to use three or four frames:
  A scrollable frame to show the hierarchy
  A frame to show what's currently selected
  A frame to title the page and tell you what to do
  Perhaps a "footer" frame to display copyright information, etc.

Yes, it CAN be done and (with a clear head) it's not very hard. At the bottom of this article, you'll find the source code of an example that navigates through a directory tree. You are welcome to cut and paste and use this example for your own purposes, but remember that it's just a demo and it's up to YOU to ensure that it's suitable for your needs.

AN EXAMPLE OF THE USE OF FRAMES IN PHP

You may run this example via
http://www.wellho.net/demo/framed_dpd.php4
Some interesting things to note:
 - The use of sessions
 - The same script to generate all the frames and the frameset
 - The "name=here" to scroll the left frame correctly
 - The separation of the PHP and HTML as far as possible
 - recursion used in expand_dir()
 - global $tree to share a variable though all recursion levels
 - The "heavy compute" making up the tree done just once

<?php

$making = "whc_outline";
if ($_GET[frame] == "whc_top") $making = "whc_top";
if ($_GET[frame] == "whc_left") $making = "whc_left";
if ($_GET[frame] == "whc_right") $making = "whc_right";
if ($_GET[frame] == "whc_bottom") $making = "whc_bottom";
if ($_GET[done]) $making = "report";

# Demonstration of navigating through a directory hierarcy
# Uses sessions so that several visitors can be selecting at the same time

session_start();

function expand_dir($sd,$nlev) {
 global $tree;
 $contains = opendir($sd);
 while ($current = readdir($contains)) {
  if (ereg('^\.',$current)) continue;
  $full = "$sd/$current";
  if (is_dir($full)) {
   array_push($tree,"$nlev 1 0 $full");
   expand_dir($full,$nlev+1);
  } else {
   array_push($tree,"$nlev 0 0 $full");
  }
 }
 }

# If this is a new session, set up the directory tree with nothing selected

if (! $_SESSION[running]) {
 $source = "../../trainee";
 $tree = array("0 1 1 $source");
 expand_dir($source,1);
 $_SESSION[tree] = $tree;
 $_SESSION[running] = 1;
}

# Deal with any selection / deselection items

if ($making == "whc_outline" or $_GET[trigger]) {
$elat = -1;
if ($_GET[ac] != "") {
for ($k=0; $k<count($_SESSION[tree]); $k++) {
 list($level,$isdir,$shown,$value) = explode(" ",$_SESSION[tree][$k]);
 if ($value == $_GET[el]) {
  $shown = ($_GET[ac] == "ex") ? 1 : 0;
  $_SESSION[tree][$k] = implode(" ",array($level, $isdir, $shown, $value));
  $elat = $k;
  }
 }
}
$_SESSION[elat] = $elat;
}

# Parse data, making up offer tree and selected HTML strings

$showing = 0;
$position = 0; $hvname=0;
$chosen = array();
$offer = array();
foreach ($_SESSION[tree] as $element) {
 $position++;
 $bold = 0;
 list($level,$isdir,$shown,$value) = explode(" ",$element);
 if ($isdir) {
  if ($shown) {
  $showing = 1;
  $flag = "<a href=$PHP_SELF?ac=sh&el=$value&frame=whc_left&trigger=1#here>-</a>";
  } else {
  $flag = "<a href=$PHP_SELF?ac=ex&el=$value&frame=whc_left&trigger=1#here>+</a>";
  $showing = 0;
  }
  if (! $level) $flag = "&nbsp;";
 } else {
  if ($shown) {
  $flag = "<a href=$PHP_SELF?ac=sh&el=$value target=_top>DeSelect</a>";
  array_push($chosen,$value);
  $bold = 1;
  } else {
  $flag = "<a href=$PHP_SELF?ac=ex&el=$value target=_top>Select</a>";
  }
 }
 $prefix = str_repeat("&nbsp;",$level * 2+(2-$isdir));
 $mrs = "";
 if ($isdir or $shown or $showing) {
  # following line need revisiting - when do subdirectories show??
  # if (! ($isdir == 1 and $shown == 0 and $level > 0)) { # Test
  if ($hvname == 0 and $position > $_SESSION[elat] and $_SESSION[elat] >= 0) {
   $value = "<a name=here>$value</a>";
   $mrs = " &lt;------- most recent selection";
   $hvname = 1;
  }
  if ($bold == 0) {
   array_push($offer,"$prefix $flag $value $mrs");
  } else {
   array_push($offer,"$prefix $flag <b>$value</b> $mrs");
   }
  }
  # }
 }

$word = "Currenly";
if ($_GET[done]) {
 $freport = "You have selected ".count($chosen)." item(s)<br><br>";
 foreach ($chosen as $item) {
  $owbig = filesize($item);
  $freport .= "$item which is $owbig bytes in size<br>";
  }
 session_destroy();
 $word = "Finally";
}
##################### Response page ###################
if ($making == "whc_outline") {
?>
<html><head><title>File Selector System USING FRAMES</title></head>
<frameset rows="100,*,100">
 <frame src=<?=$PHP_SELF?>?frame=whc_top name=whc_top>
 <frameset cols="66%,*">
  <frame src=<?=$PHP_SELF?>?frame=whc_left#here name=whc_left>
  <frame src=<?=$PHP_SELF?>?frame=whc_right name=whc_right>
 </frameset>
 <frame src=<?=$PHP_SELF?>?frame=whc_bottom name=whc_bottom>
</frameset>
<?php
##################################################
} elseif ($making == "whc_top") { ?>
<html><head><title>File Selector System - top frame</title></head>
<body>This demonstration lets you navigate through a directory tree, expanding and contracting
directories and selecting files of your choosing. When you select the DONE button, you'll get
a report of all the items selected in more detail.</body>
<?php
##################################################
} elseif ($making == "whc_right") { ?>
<html><head><title>File Selector System - right frame</title></head><body>
<b><?= $word ?> Selected</b><br>
<?php if (count($chosen)) {
     print (implode("<br>",$chosen));
} else {
     print "No selections yet made";
} ?></body>
<?php
##################################################
} elseif ($making == "whc_left") { ?>
<html><head><title>File Selector System - right frame</title></head><body>
<b>Selection Menu</b><br>
<?= implode("<br>",$offer); ?></body>
<?php
##################################################
} elseif ($making == "whc_bottom") { ?>
<html><head><title>File Selector System - bottom frame</title></head><body>
Please select <a href=<?= $PHP_SELF ?>?done=1 target=_top>done</a> or make (further)
choices from the left selector box<br><br>
Example by Well House Consultants, Copyright <?= date("Y") ?>
<br>Want to know how to do this?
<a href=http://www.wellho.net/course/ph.html>Learn Here!</a>
</body>
<?php
##################################################
} else { # result report
?>
<html><head>
<title>Report on your selection</title>
</head><body>
<h2>Here are the examples that you chose</h2>
<?=$freport?><br>
<a href=<?=$PHP_SELF?>>Restart demo</a><br>
<a href=http://www.wellho.net>Our Home Page</a><br><br>
Example by Well House Consultants, Copyright <?= date("Y") ?>
<br>Want to know how to do this?
<a href=http://www.wellho.net/course/ph.html>Learn Here!</a>
</body>
<?php } ?>
</html>


See also PHP Course details

Please note that articles in this section of our web site were current and correct to the best of our ability when published, but by the nature of our business may go out of date quite quickly. The quoting of a price, contract term or any other information in this area of our website is NOT an offer to supply now on those terms - please check back via our main web site

Related Material

PHP - Further Web Page and Network Handling
  [220] - ()
  [314] - ()
  [345] - ()
  [356] - ()
  [372] - ()
  [376] - ()
  [410] - ()
  [425] - ()
  [443] - ()
  [451] - ()
  [484] - ()
  [537] - ()
  [542] - ()
  [565] - ()
  [603] - ()
  [675] - ()
  [767] - ()
  [789] - ()
  [847] - ()
  [904] - ()
  [936] - ()
  [1009] - ()
  [1114] - ()
  [1183] - ()
  [1187] - ()
  [1210] - ()
  [1355] - ()
  [1379] - ()
  [1485] - ()
  [1495] - ()
  [1496] - ()
  [1505] - ()
  [1515] - ()
  [1518] - ()
  [1549] - ()
  [2632] - ()
  [2679] - ()
  [2729] - ()
  [2918] - ()
  [3036] - ()
  [3432] - ()
  [3540] - ()
  [3568] - ()
  [3918] - ()
  [4070] - ()
  [4483] - ()

Web and Intranet - Frames
  [220] - ()

resource index - PHP
Solutions centre home page

You'll find shorter technical items at The Horse's Mouth and delegate's questions answered at the Opentalk forum.

At Well House Consultants, we provide training courses on subjects such as Ruby, Lua, Perl, Python, Linux, C, C++, Tcl/Tk, Tomcat, PHP and MySQL. We're asked (and answer) many questions, and answers to those which are of general interest are published in this area of our site.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/solutions/php-usin ... h-php.html • PAGE BUILT: Wed Mar 28 07:47:11 2012 • BUILD SYSTEM: wizard