View Full Version : PHP Help.
Hunter
April 28th, 2009, 04:22 PM
1. Hey all. Short question is I want to be able to click on a link on my page, that click will then tell the PHP code...
<php? include "content/3d.html"; ?>
...to activate which will make the html file load into the page, then when I click on another link, it will do the same thing, but load a different html file and clear the other one.
I have herd of some code like (part of it);
"doc.write"
Or something like that.
--------------------------------------------------------------------
2. The html file also contains the same code as above...
<php? include "content/3d.html"; ?>
...but loading other html files into it. I am guessing I am going have to change that 3d.html to a .php file.
:highfive:
Found the document.write thing.
document.write('Hello World');
Could I use that like this?
<a href="#" onlick="document.write('link to file');">Blah</a>
But if I can do something like that - I know that code above IS wrong - how would I define where it loads the file as I want it to load in a certain place.
Hunter
April 30th, 2009, 08:29 AM
Oh come on. Someone must know. Bacon, where are you?
klange
April 30th, 2009, 03:20 PM
You're going to want to use some AJAX-like routines to pull in your next few documents. If your included pages use only PHP to do their includes, we can ignore them for now and just stick to the page with the dynamic loading. If your included pages will also request things, then it'll be a bit trickier to deal with the multiple pulling functions.
Anyway, the basic process is as follows:
- We've loaded our HTML document (or the result of a PHP script) and it has your dynamic load link
- That link points to either javascript:include_file("content/3d.php"); or #, with an appropriate onclick.
- Now we need to write include_file, which will look a bit like AJAX, only we don't need to extract any information:
<html>
<head>
<script type="text/javascript">
var http = false;
if(navigator.appName == "Microsoft Internet Explorer") {
http = new ActiveXObject("Microsoft.XMLHTTP");
} else {
http = new XMLHttpRequest();
}
function include_file(target) {
http.open("GET", target, true);
http.send(null);
}
http.onreadystatechange=function() {
if(http.readyState == 4) {
document.getElementById('content').innerHTML = http.responseText;
}
}
</script>
</head>
<body>
<a href="#" onclick="include_file('test.htm')">Do it</a>
<div id="content">
(This gets replaced, this is div is necessary)
</div>
</body>
</html>
Hunter
May 1st, 2009, 09:04 AM
Thanks bacon.
1. Can I use the php page with that instead of text.htm?
2. How can I make it use multiple pages? So when I click another link it would bring in a difference php file like aboutme.php ect...
<html>
<head>
<script type="text/javascript">
var http = false;
if(navigator.appName == "Microsoft Internet Explorer") {
http = new ActiveXObject("Microsoft.XMLHTTP");
} else {
http = new XMLHttpRequest();
}
function include_file(target) {
http.open("GET", target, true);
http.send(null);
}
http.onreadystatechange=function() {
if(http.readyState == 4) {
document.getElementById('content').innerHTML = http.responseText;
}
http.onreadystatechange=function() {
if(http.readyState == 4) {
document.getElementById('content2').innerHTML = http.responseText;
}
}
</script>
</head>
<body>
<a href="#" onclick="include_file('3d.php')">Do it</a>
<div id="content">
(This gets replaced, this is div is necessary)
</div>
</body>
</html>
klange
May 1st, 2009, 11:13 AM
1. Yes
2. If you want to put it in the same place (that is, replace the content), you can just do a different include_file(). If you want to put it somewhere else, we'll need to make some changes to the JS and move the onreadystatechange part to inside include_file() (before the .send()), and replace the 'content' div name with a variable (and add it to the header), then add all the divs you need and update your calls to reflect the added variable.
<html>
<head>
<script type="text/javascript">
var http = false;
if(navigator.appName == "Microsoft Internet Explorer") {
http = new ActiveXObject("Microsoft.XMLHTTP");
} else {
http = new XMLHttpRequest();
}
function include_file(target, content_div) {
http.open("GET", target, true);
http.onreadystatechange=function() {
if(http.readyState == 4) {
document.getElementById(content_div).innerHTML = http.responseText;
}
}
http.send(null);
}
</script>
</head>
<body>
<a href="#" onclick="include_file('test.htm','content')">Do it</a> <a href="#" onclick="include_file('blahblahblah.htm','content2')">Do the other thing</a>
<div id="content">
(This gets replaced, this is div is necessary)
</div>
<div id="content2">
(this gets replaced by the second link)
</div>
</body>
</html>
Hunter
May 1st, 2009, 01:16 PM
So like this?
<html>
<head>
<script type="text/javascript">
var http = false;
if(navigator.appName == "Microsoft Internet Explorer") {
http = new ActiveXObject("Microsoft.XMLHTTP");
} else {
http = new XMLHttpRequest();
}
function include_file(target) {
http.open("GET", target, true);
http.send(null);
}
http.onreadystatechange=function() {
if(http.readyState == 4) {
document.getElementById('content').innerHTML = http.responseText;
}
http.onreadystatechange=function() {
if(http.readyState == 4) {
document.getElementById('content2').innerHTML = http.responseText;
}
}
</script>
</head>
<body>
<a href="#" onclick="include_file('3d.php')">3D Work</a>
<a href="#" onclick="include_file('2d.php')">2D Work</a>
<a href="#" onclick="include_file('aboutme.php')">About Me</a>
<div id="content">
(This gets replaced, this is div is necessary)
</div>
</body>
</html>
klange
May 1st, 2009, 06:25 PM
You seem to have kept your second onreadystatechange=... remove it.
Hunter
May 1st, 2009, 07:06 PM
So without the second onreadystatechange=... it will work?
Would +rep but need to spread around. Thanks bacon.
Edit: Is this a server side script? Because it does not seem to do anything locally.
klange
May 1st, 2009, 07:25 PM
So without the second onreadystatechange=... it will work?
Would +rep but need to spread around. Thanks bacon.
Edit: Is this a server side script? Because it does not seem to do anything locally.
Copy the code from my first post exactly, create a file called test.htm in the same directory, and see if it works. It should.
Hunter
May 1st, 2009, 07:28 PM
Nope :(
Copied the exact code from your first post and saved it as test2.php.
Changed the link into this though:
<a href="#" onclick="include_file('test.html')">3D Work</a>Then made another page named test.html and put this in it:
<div>
Test Document
</div>
Edit:
It works now, I didnt copy the code from the first post. I copied;
<html>
<head>
<script type="text/javascript">
var http = false;
if(navigator.appName == "Microsoft Internet Explorer") {
http = new ActiveXObject("Microsoft.XMLHTTP");
} else {
http = new XMLHttpRequest();
}
function include_file(target) {
http.open("GET", target, true);
http.send(null);
}
http.onreadystatechange=function() {
if(http.readyState == 4) {
document.getElementById('content').innerHTML = http.responseText;
}
http.onreadystatechange=function() {
if(http.readyState == 4) {
document.getElementById('content2').innerHTML = http.responseText;
}
}
</script>
</head>
<body>
<a href="#" onclick="include_file('3d.php')">3D Work</a>
<a href="#" onclick="include_file('2d.php')">2D Work</a>
<a href="#" onclick="include_file('aboutme.php')">About Me</a>
<div id="content">
(This gets replaced, this is div is necessary)
</div>
</body>
</html>
Thanks Bacon.
klange
May 1st, 2009, 07:33 PM
http://oasisa.oasis-games.com/ajaxtest.htm#
Odd. Working fine for me... Hm...
Hunter
May 1st, 2009, 07:43 PM
For some reason it isnt working even though I copied everything into my document right... Could you have a look bacon, and please ignore the messy code, I need to look through it and remove un-needed 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>Martyn Lee Ball - 3D</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<link href="alt-styles/red.css" rel="alternate stylesheet" type="text/css" title="red">
<link href="alt-styles/green.css" rel="alternate stylesheet" type="text/css" title="green">
<link href="alt-styles/pink.css" rel="alternate stylesheet" type="text/css" title="pink">
<script type="text/javascript" src="styleswitcher.js"></script>
<script type="text/javascript">
var http = false;
if(navigator.appName == "Microsoft Internet Explorer") {
http = new ActiveXObject("Microsoft.XMLHTTP");
} else {
http = new XMLHttpRequest();
}
function include_file(target) {
http.open("GET", target, true);
http.send(null);
}
http.onreadystatechange=function() {
if(http.readyState == 4) {
document.getElementById('content').innerHTML = http.responseText;
}
}
</script>
<a href="#"
onclick="setActiveStyleSheet('default'); return false;" rel="nofollow">Blue</a>
<a href="#"
onclick="setActiveStyleSheet('red'); return false;" rel="nofollow">Red</a>
<a href="#"
onclick="setActiveStyleSheet('green'); return false;" rel="nofollow">Green</a>
<a href="#"
onclick="setActiveStyleSheet('pink'); return false;" rel="nofollow">Pink</a>
<a name="top"></a>
</head>
<body>
<!--TITLE TABLE!-->
<table border="1" width="700" height="auto" align="center" bordercolor="#446688">
<td>
<?php inlcude "title.html"; ?>
</td>
<tr></tr>
</table>
<!--TITLE TABLE END!-->
<table class="navbar" width="700" align="center" border="0">
<tr>
<td>
<?php include "pages/navbar.html"; ?>
<a href="#" onclick="include_file('3d.php')">Test Menu</a>
</tr>
</td>
</table>
<table class="content" width="700" align="center" border="0">
<tr>
<td rowspan="2">
<!-- Date !-->
<div class="update">
UPDATED: THURDAY, 02 APRIL 2009
</div>
<!-- Date End !-->
<!-- Main Content Begin !-->
<div class="content">
(Will display here)
</div>
<!-- Main Content End !-->
</td>
</table>
<!-- Footer !-->
<table class="copyright" width="700" align="center" border="0">
<div class="update" align="center">© COPYRIGHT - MARTYN LEE BALL - 2009</div>
</table>
<!-- Footer End !-->
<!-- Links !-->
<center>
<div class="ads">
<a href="http://www.modacity.net" target="_blank"><img src="ads/modacity.jpg"></a>
<a href="http://www.halomaps.org" target="_blank"><img src="ads/halomaps.jpg"></a>
<a href="http://www.modhalo.net/" target="_blank"><img src="ads/modhalo.gif"></a>
<a href="http://www.deviantart.com/" target="_blank"><img src="ads/deviantart.jpg"></a>
</div>
</center>
<!-- Links End !-->
</body>
</html>
klange
May 1st, 2009, 09:41 PM
The function may not be able to find the <div> it's looking for.
The DOM can do funny things like that...
Hunter
May 2nd, 2009, 07:00 AM
The page isnt even loading now :confused2:
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/content/s/u/p/supavitax64/html/h3mt/temp/index.php on line 40
Keep getting crap like that, I dont see anything wrong with the code...
Line 40:
<td><?php inlcude "title.html"; ?></td>
klange
May 2nd, 2009, 11:33 AM
You spelled include wrong.
Hunter
May 3rd, 2009, 05:38 PM
Lmfao. Im an idiot.
Hunter
May 7th, 2009, 10:43 AM
I spelt it right this time, but its still being a prick to me. :mad:
index.php
<!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>Martyn Lee Ball - 3D</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<link href="alt-styles/red.css" rel="alternate stylesheet" type="text/css" title="red">
<link href="alt-styles/green.css" rel="alternate stylesheet" type="text/css" title="green">
<link href="alt-styles/pink.css" rel="alternate stylesheet" type="text/css" title="pink">
<script type="text/javascript" src="styleswitcher.js"></script>
<script type="text/javascript">
var http = false;
if(navigator.appName == "Microsoft Internet Explorer") {
http = new ActiveXObject("Microsoft.XMLHTTP");
} else {
http = new XMLHttpRequest();
}
function changeContent(target) {
http.open("GET", target, true);
http.send(null);
}
http.onreadystatechange=function() {
if(http.readyState == 4) {
document.getElementById('content_r').innerHTML = http.responseText;
}
}
</script>
</head>
<body>
<a href="#"
onclick="setActiveStyleSheet('default'); return false;" rel="nofollow">Blue</a> <a href="#"
onclick="setActiveStyleSheet('red'); return false;" rel="nofollow">Red</a> <a href="#"
onclick="setActiveStyleSheet('green'); return false;" rel="nofollow">Green</a> <a href="#"
onclick="setActiveStyleSheet('pink'); return false;" rel="nofollow">Pink</a> <a name="top"></a>
<!--TITLE TABLE!-->
<table id="title_table" border="1" width="700" align="center">
<td>
<?php include "title.html" ?>
</td>
</table>
<!--TITLE TABLE END!-->
<!-- NAVBAR START !-->
<table class="navbar" width="700" align="center" border="0">
<tr>
<td><?php include "pages/navbar.html"; ?>
<a href="#" onclick="changeContent('test.php')">Test Menu</a>
</tr>
</td>
</table>
<!-- NAVBAR END !-->
<table class="content" width="700" align="center" border="0">
<tr>
<td rowspan="2"><!-- Date !-->
<div class="update"> UPDATED: THURDAY, 02 APRIL 2009 </div>
<!-- Date End !-->
<!-- Main Content Begin !-->
<div class="content_r"> (Will display here) </div>
<!-- Main Content End !--></td>
</table>
<!-- Footer !-->
<table class="copyright" width="700" align="center" border="0">
<div class="update" align="center">© COPYRIGHT - MARTYN LEE BALL - 2009</div>
</table>
<!-- Footer End !-->
<!-- Links !-->
<center>
<div class="ads"> <a href="http://www.modacity.net" target="_blank"><img src="ads/modacity.jpg" alt="blank_"></a> <a href="http://www.halomaps.org" target="_blank"><img src="ads/halomaps.jpg" alt="blank_"></a> <a href="http://www.modhalo.net/" target="_blank"><img src="ads/modhalo.gif" alt="blank"></a> <a href="http://www.deviantart.com/" target="_blank"><img src="ads/deviantart.jpg" alt="blank"></a> </div>
</center>
<!-- Links End !-->
</body>
</html>
----------------------------------------------------------------------
test.php
<div>Test Content</div>
Also, I will proboably be changing the whole websit to this:
http://i58.photobucket.com/albums/g268/martynball/website_edumicro.png
Still a big WIP, inspired by Edumicro (http://edumicro.deviantart.com/).
Another problem:
How can I make the circled divs go next to each other instead of below each other?
http://i58.photobucket.com/albums/g268/martynball/div_align.jpg
klange
May 7th, 2009, 05:12 PM
To make the divs go horizontal, I'd either float them (can totally screw up formatting) or just put them in table cells.
The other problem: your div needs an id to be called through GetById(), add id="content_r" to it and it should work (in theory).
Hunter
May 7th, 2009, 05:37 PM
I have been told tables are bad for layout. Also, if I use a table, how can I make it so the sides are right up to the left and rightt, so there are no gaps in the sides between the background image and sides of browser?
klange
May 7th, 2009, 05:39 PM
I have been told tables are bad for layout. Also, if I use a table, how can I make it so the sides are right up to the left and rightt, so there are no gaps in the sides between the background image and sides of browser?
There are some things, like columns of this sort, that are exactly what tables should be used for. Plus, you're already using tables, there's no point trying to avoid any more of them.
width=100% (on the <table>) ?
Hunter
May 7th, 2009, 05:47 PM
So we have..
<table width="100%" border="0">
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
How can I define each collumn to have a certain background image using CSS?
Never mind, just noticed I can add class="" tags in the <td> parts. Lol
Im a propa nub with code Lol.
Hunter
May 7th, 2009, 06:03 PM
How do I get rid of these spaces between the images? I am guessing the table is causing it, the border is set to "0". Also, I have added width="100%" but as you can see, there are still gaps on the side.
http://i58.photobucket.com/albums/g268/martynball/space_table.jpg
klange
May 7th, 2009, 06:12 PM
border-width: 0px;
border-spacing: 0px;
border-style: none none none none;
border-collapse: collapse;
Try any and all of these.
Hunter
May 7th, 2009, 06:17 PM
I added the for properties to all of the tables and it looks the same :/
Get on AIM Bacon.
klange
May 7th, 2009, 08:47 PM
I'm on AIM, make sure you use my full screename: kevin.lange@oasis-games.com - silly vB cuts it off.
Hunter
May 8th, 2009, 03:51 AM
I will add you tonight, got to go college now, going to be late.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.