using includes (as templates)

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!

Moderator: General Moderators

Post Reply
iceangel89
Forum Commoner
Posts: 39
Joined: Mon Jul 02, 2007 7:02 pm

using includes (as templates)

Post by iceangel89 »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


i use dreamweaver and have problems with using DW's templates with PHP code so i used includes. 

like this:
[b]Main Template[/b]

Code: Select all

<?php include "_include_header.php";?>
<?php include "_include_html0.php"; ?>
<title></title>
<?php include "_include_html.php"; ?>
  <h2>Home</h2>
  <p> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam  egestas, orci ac dapibus vehicula, tellus ante pharetra lorem, ut  egestas elit orci eget lorem. Phasellus velit purus, tempor vel,  aliquet eu, ultricies non, dui. Nulla nec tellus. Phasellus nonummy  sodales odio. Quisque nulla risus, lobortis vitae, imperdiet rhoncus,  porta at, est. Nullam commodo, orci sed consequat volutpat, tortor  magna mattis lectus, vitae tristique urna orci sit amet nibh. Curabitur  adipiscing, dolor sit amet ullamcorper aliquam, erat ipsum aliquam  orci, nec nonummy leo felis nec dui. Integer ut risus suscipit quam  consectetuer congue. Praesent eget justo. Morbi pede. Aliquam id erat.  Fusce augue massa, egestas vitae, hendrerit ac, ullamcorper non, elit. </p>
<?php 
include "_include_footer.php";
?>
_include_header.php PHP code for use in (common) HTML code - like "Logged in as ..."

Code: Select all

<?php require_once('../Connections/conn.php'); ?>
<?php
if (!isset($_SESSION)) {
	session_start();
}
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$colname_rsUserdata = "-1";
if (isset($_SESSION['UserID'])) {
  $colname_rsUserdata = $_SESSION['UserID'];
}
mysql_select_db($database_conn, $conn);
$query_rsUserdata = sprintf("SELECT UserID, Username, UserGroup FROM users WHERE UserID = %s", GetSQLValueString($colname_rsUserdata, "int"));
$rsUserdata = mysql_query($query_rsUserdata, $conn) or die(mysql_error());
$row_rsUserdata = mysql_fetch_assoc($rsUserdata);
$totalRows_rsUserdata = mysql_num_rows($rsUserdata);
?>

_include_html0.php
HTML until <head>

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="version2.css" rel="stylesheet" type="text/css" />
_include_html.php common HTML template - banner etc

Code: Select all

</head>

<body>
<h1>Sun<span class="sun">Flower</span>.com</h1>
<div id="topNav_Main" class="domtab"><a href="#">Home</a> | <a href="#">Journals</a>
  <?php if ($row_rsUserdata['UserGroup'] == "Admin") { // Show if admin ?>
    <span class="blue"> | [Admin]</span> <a href="#">Publish journal</a> | <a href="#">Manage Users</a>
    <?php } elseif ($row_rsUserdata['UserGroup'] == "Author") { // else if publisher ?>
<span class="blue"> | [Author]</span> <a href="#">Upload journal</a><?php } ?> </div>

<div id="topNav_Extras">
  <?php if ($totalRows_rsUserdata > 0) { // Show if recordset not empty ?>
    Logged in as ... <a href="#"><?php echo $row_rsUserdata['Username']; ?></a>, [<span class="usergroup"><?php echo $row_rsUserdata['UserGroup']; ?></span>]<?php } // Show if recordset not empty ?>
  <?php if ($totalRows_rsUserdata == 0) { // Show if recordset empty ?>
      You are not logged in <a href="../login.php">Login</a> | <a href="../register.php">Register</a>
  <?php } // Show if recordset empty ?>
</div> 

  
<div id="center">
<?php
mysql_free_result($rsUserdata);
?>
as [s]u[/s] you can see there are duplicates of session_start() generated by Dreamweaver, mysql_free_result() sometimes appear in different places causing errors. < must mysql_free_result() be in the same include file? how do i resolve such problems? and is my "Main Template" correct, as in its abit difficult to have/manage so many includes? i have that many incluues so that i can have <title> for each page, and i separated _include_header.php with _include_html0.php so that extra PHP code that needs to be generated by Dreamweaver can be done and not produce error about outside <html> being locked


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

[quote="[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1"][b]11.[/b] Please use proper, complete spelling when posting in the forums. AOL Speak, leet speak and other abbreviated wording can confuse those that are trying to help you (or those that you are trying to help). Please keep in mind that there are many people from many countries that use our forums to read, post and learn. They do not always speak English as well as some of us, nor do they know these aberrant abbreviations. Therefore, use as few abbreviations as possible, especially when using such simple words.

Some examples of what not to do are ne1, any1 (anyone); u (you); ur (your or you're); 2 (to too); prolly (probably); afaik (as far as I know); etc.[/quote]
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

You could invert your template scheme and put header, html0, html1 and footer into a single template that includes a specified page's content.
(#10850)
Post Reply