d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Please Help
Add Reply New Topic New Poll
Member
Posts: 4,103
Joined: Dec 11 2013
Gold: 0.00
Jun 16 2014 11:07pm
Okay so I am just now learning some of this in school. I'm trying to store all of the code for the top of the website in styles/top.php (styles folder, and page called top.php) and the code for the bottom of the website in styles/bottom.php

and when I try and connect these to my index.php it just shows the code that is in my index.php file:

<?php require("styles/top.php"); ?>
<div id='full'>content here</div>

<div id='left'>left side</div>

<div id='right'>right side</div>
<?php require("styles/bottom.php"); ?>

what do i need to do so that these will connect together and work.
Member
Posts: 29,723
Joined: Jun 11 2007
Gold: 279.52
Jun 16 2014 11:52pm
use include instead of require

Code
<?php include("styles/top.php"); ?>


and make sure that that index IS a php file.

you can also use require_once

Code
<?php require_once("styles/top.php"); ?>


This post was edited by AkuuZ on Jun 16 2014 11:53pm
Member
Posts: 4,103
Joined: Dec 11 2013
Gold: 0.00
Jun 17 2014 01:35pm
Quote (AkuuZ @ Jun 16 2014 11:52pm)
use include instead of require

Code
<?php include("styles/top.php"); ?>


and make sure that that index IS a php file.

you can also use require_once

Code
<?php require_once("styles/top.php"); ?>


Both options are not working,

index is a php file, in my folder. NOT IN STYLES folder like top.php and bottom.php are. Do I need to put it in there?
Member
Posts: 4,103
Joined: Dec 11 2013
Gold: 0.00
Jun 17 2014 02:19pm
this currently whats in top.php,

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>dddd.com</title>
<link href='styles/main.css' rel='stylesheet' type='text/css'></link>
<style type='text/css'>
<!--
body{
background-color: #E2DECF;
}
-->
</style>
</head>
<body>

<div id='wrapper'>

<div id='header'><a href='http://www.dddd.com/'><img src='images/logo.png'></img></a></div>

<div id='nav'>
<a href='#'>Home</a><a href='#'>Link</a><a href='#'>Link</a><a href='#'>Link</a><a href='#'>Link</a>
</div>

<div id='content'>


bottom.php has the following,

Code

</div>

<div id='footer'>
<a href='source_code.php'>Source Code</a>
</div>

</div>

</body>
</html>


and index.php which is in my dddd.com folder is,

Code
<?php require("styles/top.php"); ?>
<div id='full'>content here</div>

<div id='left'>left side</div>

<div id='right'>right side</div>
<?php require("styles/bottom.php"); ?>


Now for some reason my index.php file is not linking the top.php and bottom.php files together so that it still looks as if the code was all in index.php.

I was following a youtube tutorial on how to link the seperate pages together and it looks like I have everything correct. But for some reason it just shows the code when I run index.php.

I can give donations for help.
Member
Posts: 649
Joined: May 28 2012
Gold: 14.00
Jun 17 2014 02:22pm
Do you have return statement in you top.php and bottom.php ?

Because you need them if you want your include statement showing the content of top.php/bottom.php, else, if you have no return in top.php/bottom.php, include will return 1 (if include is ok) or 0 (if your include failed)


edit: posted before seeing your last reply

Your bottom.php and top.php do not need to have .php extension since it's just html so I would suggest renaming them and edit your index.php with new names

This post was edited by FCNantes on Jun 17 2014 02:27pm
Member
Posts: 4,103
Joined: Dec 11 2013
Gold: 0.00
Jun 17 2014 02:28pm
Quote (FCNantes @ Jun 17 2014 02:22pm)
Do you have return statement in you top.php and bottom.php ?

Because you need them if you want your include statement showing the content of top.php/bottom.php, else, if you have no return in top.php/bottom.php, include will return 1 (if include is ok) or 0 (if your include failed)

edit: posted before seeing your last reply

Your bottom.php and top.php do not need to have .php extension since it's just html so I would suggest renaming them and edit your index.php with new names


I am sorry can you give example of what I would rename too?

bottom.html?
top.html?
index.html?
but I will be doing php coding
I am trying to code a community site, so eventually I will have php coding

This post was edited by earStash on Jun 17 2014 02:29pm
Member
Posts: 649
Joined: May 28 2012
Gold: 14.00
Jun 17 2014 02:29pm
Quote (earStash @ 17 Jun 2014 22:28)
I am sorry can you give example of what I would rename too?

bottom.html?
top.html?
index.html?
but I will be doing php coding


bottom.html
top.html
index.php

and in index.php rename bottom.php to bottom.html and top.php to top.html
Member
Posts: 4,103
Joined: Dec 11 2013
Gold: 0.00
Jun 17 2014 02:45pm
okay so apparently I need to install easyphp so i can host it through my own PC.
Member
Posts: 29,723
Joined: Jun 11 2007
Gold: 279.52
Jun 17 2014 04:24pm
Oh your not running a it live or through a test server?

xampp is usually what i use as a test server.

php needs a server to run on lol.

ignore what guy said about the html extension. it doesnt matter whats in your .php file, it would still include it.
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll