batstanggt Posted July 25, 2011 Share Posted July 25, 2011 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 Quote Link to comment Share on other sites More sharing options...
teynon Posted July 25, 2011 Share Posted July 25, 2011 Can we see your code? Also, <a href="layout.php?id=main.html> There is no end quote. I don't think that will effect it, but either way, I'd fix it. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted July 25, 2011 Share Posted July 25, 2011 Are you trying to retrieve an external HTML PAGE, or does it reside on the server. Quote Link to comment Share on other sites More sharing options...
batstanggt Posted July 25, 2011 Author Share Posted July 25, 2011 It resides on the server Sensei.... -SB Quote Link to comment Share on other sites More sharing options...
teynon Posted July 25, 2011 Share Posted July 25, 2011 batstanggt, we need to see all of your code to see how you are handling the variables, etc. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted July 25, 2011 Share Posted July 25, 2011 It resides on the server Sensei.... -SB Alright, as mentioned by teynon , we would need to see the full codes of the layout.php and includes. Quote Link to comment Share on other sites More sharing options...
batstanggt Posted July 25, 2011 Author Share Posted July 25, 2011 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 ... Quote Link to comment Share on other sites More sharing options...
teynon Posted July 25, 2011 Share Posted July 25, 2011 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. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted July 25, 2011 Share Posted July 25, 2011 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 ... Quote Link to comment Share on other sites More sharing options...
batstanggt Posted July 25, 2011 Author Share Posted July 25, 2011 Thank again guys, Sensei and Teyvon how do I write the link in the <a href> so that it knows which page to put there or is that being done correctly ? -SB Quote Link to comment Share on other sites More sharing options...
teynon Posted July 25, 2011 Share Posted July 25, 2011 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}"; ?> Quote Link to comment Share on other sites More sharing options...
batstanggt Posted July 25, 2011 Author Share Posted July 25, 2011 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 Quote Link to comment Share on other sites More sharing options...
teynon Posted July 25, 2011 Share Posted July 25, 2011 Can you put this on a live server we can see the output? If not, view the source and post it here. Quote Link to comment Share on other sites More sharing options...
batstanggt Posted July 25, 2011 Author Share Posted July 25, 2011 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 Quote Link to comment Share on other sites More sharing options...
teynon Posted July 25, 2011 Share Posted July 25, 2011 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.