Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-30-2012, 10:57 AM   PM User | #1
CrazyCrisUk
New Coder

 
Join Date: Jan 2011
Posts: 42
Thanks: 5
Thanked 0 Times in 0 Posts
CrazyCrisUk is an unknown quantity at this point
Declaring a variable before it is set..... output buffering??

I want to use a variable in the <title></title> to display the name of the article being shown on the page.

Each page uses an included header and footer file, and output buffering is being used.

So each page starts like this..

PHP Code:
<?
$page_title 
"Page Title";
include 
'header.php';
include 
'footer.php';
?>
...and header.php echos out the $page_title in the title tag.

However I want the $page_title varible to reflect the actual name of the article, which is set dynamically in the $article_title variable further down the page. Something like..

PHP Code:
<?
$page_title 
$article_title;
include 
'header.php';
$article_title $result['title'];
include 
'footer.php';
?>
But of course due to the way I'm including the header this needs to be put before the variable is actually set causing the problem.

I already use output buffering, is there a way i can use this to help? This has to be quite a common problem I think...

Thanks in advance! This has been a problem to me for a while and I can't figure out the best way around it!!
CrazyCrisUk is offline   Reply With Quote
Old 01-30-2012, 11:12 AM   PM User | #2
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,689
Thanks: 158
Thanked 2,184 Times in 2,171 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
Quote:
Originally Posted by aedrin View Post
You should really look into seperating out the various parts of your site. Think along the lines of a template (without using a templating system) for the main design. Seperate each page into 2 sections, a model and a view. Execute the model before you display anything. It will parse all the incoming data and prepare the data to be displayed. Then as you're displaying the main template, include the view for the current page wherever your template holds the output of the page.

This allows you to set the title in the model. Which solves the chicken before the egg problem
See http://www.codingforums.com/showthread.php?t=129123
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Old 01-30-2012, 12:24 PM   PM User | #3
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,667
Thanks: 46
Thanked 456 Times in 444 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Output buffering simply stops headers being sent. It doesn't allow you to change what has already been printed to the HTML - as far as I know anyway.

What you need to do, is seperate your html and PHP. Run the php FIRST and then put all the generated content into the html.
__________________
Please don't be rude: Put your php code in [php][/php] tags. It is a sticky topic at the top of the forum and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Old 01-30-2012, 12:40 PM   PM User | #4
jmj001
Regular Coder

 
Join Date: Jan 2012
Posts: 271
Thanks: 2
Thanked 65 Times in 65 Posts
jmj001 is an unknown quantity at this point
post the contents of your header.php file here... there will be a way for it to work..
jmj001 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:53 AM.


Advertisement
Log in to turn off these ads.