Current location: Hot Scripts Forums » Programming Languages » PHP » variable name in includes statement problem


variable name in includes statement problem

Reply
  #1 (permalink)  
Old 02-24-10, 02:46 PM
adr2020 adr2020 is offline
New Member
 
Join Date: Feb 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
variable name in includes statement problem

I would like to use variable names for include statement & title tag info.

index.php
PHP Code:

<?php
$pagetitle 
"Mysite - Home";
$bodycontent "index.htm";
include(
"bodycontent.php");
?>
Then,
PHP Code:

<html><head>
<?php <title>$pagetitle</title?>
</head>

<body>

<?php include("includes/top.htm"?>
<table>
    <?php include("includes/left.htm"?>
    <?php include("includes/")$bodycontent?>
</table>
<?php include("includes/bottom.htm"?>
</body></html>
The index page doesnt show anything. The reason I'd like to use variable names for the title & include file is so I dont have to change the page structure code on all the separate PHP pages, so they all look to "include" the pagecontent. What needs to be corrected in the code to have it work?
Alan (kind of newbie)

Last edited by job0107; 02-24-10 at 03:39 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 02-24-10, 03:40 PM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Try it like this:
PHP Code:

<?php
$pagetitle 
"Mysite - Home";
$bodycontent "index.htm";
include(
"bodycontent.php");
?>
<html>
<head>
<?php echo "<title>$pagetitle</title>"?>
</head>
<body>
<?php include("includes/top.htm"?>
<table>
<?php include("includes/left.htm"?>
<?php 
include("includes/$bodycontent"); ?>
</table>
<?php include("includes/bottom.htm"?>
</body>
</html>
__________________
Jerry Broughton
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 02-25-10, 11:07 AM
adr2020 adr2020 is offline
New Member
 
Join Date: Feb 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Jerry, Thanks. The echo $pagetitle shows. All the includes are showing now, but the following code line:
<?php include("includes/$bodycontent"); ?>

Any idea how to resolve this?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 02-25-10, 11:53 AM
adr2020 adr2020 is offline
New Member
 
Join Date: Feb 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by adr2020 View Post
Jerry, Thanks. The echo $pagetitle shows. All the includes are showing now, but the following code line:
<?php include("includes/$bodycontent"); ?>

Any idea how to resolve this?
I even changed (index.php) code line to define the path: $bodycontent = "includes/index.htm";

and changed (bodycontent.php) code line to use only the variable: <?php include $bodycontent; ?>

It still doesnt show the contents of where the variable $bodycontent is referring to 'index.htm'

Any idea how to resolve this?

Thanks for your advise Jerry (or anyone from the Hotscripts Forum Community)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 02-26-10, 08:29 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Quote:
Originally Posted by adr2020 View Post
I even changed (index.php) code line to define the path: $bodycontent = "includes/index.htm";

and changed (bodycontent.php) code line to use only the variable: <?php include $bodycontent; ?>

It still doesnt show the contents of where the variable $bodycontent is referring to 'index.htm'

Any idea how to resolve this?

Thanks for your advise Jerry (or anyone from the Hotscripts Forum Community)
What you are saying here doesn't seem to make a lot of sense yet.

This is what the contents of my "index.htm" file looks like:
HTML Code:
<h1>This is index.htm</h1>


I have a directory called "test" and in the "test" directory I have a directory called "includes".
Also in the "test" directory I have the file called "index.php" which has my code in it and there should also be a file called "
bodycontent.php".
And in the "includes" directory I have the file called "index.htm".
Also in the "includes" directory there should be the files called "
top.htm", "left.htm" and "bottom.htm".
I don't understand what the file "bodycontent.php" is used for.

This is the contents of the file "index.php".
PHP Code:

<?php
$pagetitle 
"Mysite - Home";
$bodycontent "index.htm";
include(
"bodycontent.php");
?>
<html>
<head>
<?php echo "<title>$pagetitle</title>"?>
</head>
<body>
<?php include("includes/top.htm"?>
<table>
<?php include("includes/left.htm"); ?> 
<?php include("includes/$bodycontent"); ?>
</table>
<?php include("includes/bottom.htm"?>
</body>
</html>
But the contents of "index.php" probably should look like this:
PHP Code:

<?php
$pagetitle 
"Mysite - Home";
$bodycontent "index.htm";
?>
<html>
<head>
<?php echo "<title>$pagetitle</title>"?>
</head>
<body>
<?php include("includes/top.htm"?>
<table>
<?php include("includes/left.htm"?>
<?php 
include("includes/$bodycontent"); ?>
</table>
<?php include("includes/bottom.htm"?>
</body>
</html>
If I were to set this up, I would have the file "index.php" in my root directory.
Also in my root directory I would have a directory called "includes".
And in my "includes" directory I would have the files "top.htm", "left.htm", "bodycontent.htm" and "bottom.htm".
And then the contents of my "index.php" file would look like this:
PHP Code:

<?php
$pagetitle 
"Mysite - Home";
$bodycontent "bodycontent.htm";
?>
<html>
<head>
<?php echo "<title>$pagetitle</title>"?>
</head>
<body>
<?php include("includes/top.htm"); ?>
<table>
<?php 
include("includes/left.htm");
include(
"includes/$bodycontent"); 
?>
</table>
<?php include("includes/bottom.htm"?>
</body>
</html>
Ok, I see other problems.
Look at your includes.
They are missing some punctuation.
They are missing the semicolons.
I don't see why I didn't see that before.
My bad.
__________________
Jerry Broughton

Last edited by job0107; 02-26-10 at 09:32 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 03-13-10, 06:25 PM
adr2020 adr2020 is offline
New Member
 
Join Date: Feb 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Trophee Yes, it works great!

Jerry, Thanks. Yes, it all works like a charm. I've been meaning to get back to you, but I've been taking a "fast track" class & have been swamped. Thank you soooooo much for your guidance on this code. It works awesome!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 03-14-10, 09:53 PM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Your very welcome. Glad I could be of assistance.
__________________
Jerry Broughton
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
getting a variable to display another variable? frobak PHP 2 03-17-09 04:23 PM
a href and php variable problem dlmaster PHP 6 01-09-08 06:18 AM
templating problem (how to forward file name as a variable) skyrat PHP 0 09-11-05 09:27 PM
what is the best method to find last word in variable ? GS300 PHP 6 09-15-04 10:13 PM
SQL Statement problem jetskibum ASP 1 08-16-04 07:41 AM


All times are GMT -5. The time now is 09:12 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.