Jump to content

Includes in Div Tag


batstanggt

Recommended Posts

Hey in doing some research to solve one of my many problems I came accross this... and I tried to implement it however it doesnt seem to be working. Can someone maybe fill in the blanks here of how to make this snippet of code work within a webpage...Thanks heres the quote...

"I think frames are icky...i had to change my site completely to avoid using them. The best way to do something that would be like using frames is a SSI(server side include) I like using php includes with come variables. Basically what you do is create a layout, and have the menus and links on it, but leave the content area empty except for the php include, which is

Code: [ Download ] [ Select ]<?php include('$id'); ?>

 

id is whatever variable you want, but that comes in later. Then you create pages with just the content in it, like so

Code: [ Download ] [ Select ] [ Line Numbers Off ]

<p><b>Main page</b></p>

<p>This is my main page, using php includes</p>

 

01.<p><b>Main page</b></p>

02.<p>This is my main page, using php includes</p>

 

and you would name that page something like main.html. The way to view your layout woulb be something like this http://www.site.com/layout.php, that would show the layout without any content, and then this: http://www.site.com/layout.php?id=main.html would show the layout, with main.html included whereever you put the php include. "

Im trying to get another html page or maybe it has to be php page to load in a div when a link is clicked from a left div. The <a href that im using to try and load the hypothetical main.html page in the div is as follows ....

<a href="layout.php?id=main.html>Main </a>  and its not working.... it flashes the url changes but the html doesnt appear in the div. What am I doing wrong?
-SB

Link to comment
Share on other sites

I figure it must be something to do with variable $id not be declared but then again im prolly way off heres the code....

 

<!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" />
<title>layout</title>
<link rel="stylesheet" type="text/css" href="test.css"/>
</head>
<body>
<div id="header"><img src="picture1.jpg" width="10" height="68" align="right" />
</div>
<div id="menu" style="border:solid #FFF thin" />
<img src="picturea.gif" width="150" height="120" />
<img src="pictureb.gif" width="150" height="120"  />
<img src="imagec.gif" width="150" height="120"  /> 
<img src="imaged.gif" width="150" height="120" />
<a href="layout.php?id=main.html"/><img src="imagee.gif" width="150" height="120" /></a>
</div>
<div id="content">
<?php
include('$id');
?>
</div>
<div id="footer">
  <p>This is a footer</p>
</div>
</body>
</html>
[code]

Then the main.html code
[code]
<!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" />
<title>Untitled Document</title>
</head>

<body bgcolor="#0066FF">
<p>
<img src="itsapicture.gif" height="120" width="150" /></p>

</body>
</html>
[code]
Thanks guys ...

Link to comment
Share on other sites

You are not declaring ID.

 

You need to pull it like this:

 

<?php
   $id="default.html";
   if (isset($_GET['id'])) {
      $id=$_GET['id'];
   }
?>

 

You should note, though, that under this method, I can include any file I want including your mysql information, etc.

Link to comment
Share on other sites

You havnt defined ID try this

<!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" />
<title>layout</title>
<link rel="stylesheet" type="text/css" href="test.css"/>
</head>
<body>
<div id="header"><img src="picture1.jpg" width="10" height="68" align="right" />
</div>
<div id="menu" style="border:solid #FFF thin" />
<img src="picturea.gif" width="150" height="120" />
<img src="pictureb.gif" width="150" height="120"  />
<img src="imagec.gif" width="150" height="120"  /> 
<img src="imaged.gif" width="150" height="120" />
<a href="layout.php?id=main.html"/><img src="imagee.gif" width="150" height="120" /></a>
</div>
<div id="content">
<?php
$id = (isset($_GET['id'])) ? $_GET['id'] : "main.html";
include("$id");
?>
</div>
<div id="footer">
  <p>This is a footer</p>
</div>
</body>
</html>
[code]

Then the main.html code
[code]
<!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" />
<title>Untitled Document</title>
</head>

<body bgcolor="#0066FF">
<p>
<img src="itsapicture.gif" height="120" width="150" /></p>

</body>
</html>
[code]
Thanks guys ...

 

Link to comment
Share on other sites

index.php?id=main.html would be correct. However, if you are having errors. (Which I suspect you are.) You need to make sure that you are referencing the correct path. IE if main.html is located in a sub folder such as "content/main.html", then you need to make sure you are referencing that in the include.

 

IE:

 

<?php
   $id="default.html";
   if (isset($_GET['id'])) {
      $id=$_GET['id'];
   }
   include "content/{$id}";
?>

Link to comment
Share on other sites

The only major issue now is that the HTML page in the right div isnt displaying correctly. For somereason the image which is on the main.html page shows up so i know it loaded correctly but the blue background for somereason is just off the screen for somereason. i can see it around the outside of the right and bottom of the page but the the div is still white.

-SB

Link to comment
Share on other sites

Thanks for all your help guys seems like I got it figured out i just changed the background of the div in the external .css and took the bgcolor attribute out of the body tag in main.html. Thanks Sensei and Teynon you guys are absolute life savers.

-SB

Link to comment
Share on other sites

If you are "including" main.html via PHP, that content should not have an HTML, HEAD, or BODY tag. You are including direct html code. IE:

 

<p>This is my content.</p>

 

If you include html, head, or body tags, you are creating invalid markup.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.