Jump to content

[SOLVED] Variable running when it shouldn't


goocharlton

Recommended Posts

I have my site index.php page with this code:

<?php 
$page_name = 'News';
$page_ID = 'news';
$heading = 'News';
$content = include ('news_items.php');
include ('template.php');
?>

 

When I run index.php the code runs through the list of variables then it runs the include ('template.php'); (this is the page that runs the site template, it asks for the variables above).

 

My problem is when index.php is run the $content variable's output displays before the include ('template.php'); is displayed but it is meant to run the include ('template.php'); and then call $content into the template.

 

What am I doing wrong?

Link to comment
https://forums.phpfreaks.com/topic/59798-solved-variable-running-when-it-shouldnt/
Share on other sites

I have my site index.php page with this code:

<?php 
$page_name = 'News';
$page_ID = 'news';
$heading = 'News';
$content = include ('news_items.php');
include ('template.php');
?>

 

When I run index.php the code runs through the list of variables then it runs the include ('template.php'); (this is the page that runs the site template, it asks for the variables above).

 

My problem is when index.php is run the $content variable's output displays before the include ('template.php'); is displayed but it is meant to run the include ('template.php'); and then call $content into the template.

 

What am I doing wrong?

 

You can't assign include() to a variable (without getting a value like 1) if the included page doesn't literally return a value ( return "hi"; ). In which case, it will still include the page either way.

Hmm. Thanks infid3l but can you recommend any other way of doing what i am trying to achieve. I cannot use the method that you just mentioned because I also use news_items.php called from another file in the following way:

<?php
			if (${'left_column_' . $page_ID} == 0)
				echo "";
			else
				include_once ("left_column.php");
            ?>

 

..therefore I cannot change the news_items.php in anyway unless I can do it in a way that it can be called by the above code as well.

My 'news_items.php' file contains:

<div class="date">June 28, 2007</div>
<div class="info">Welcome to .......<br>text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text</div>

My 'news_items.php' file contains:

<div class="date">June 28, 2007</div>
<div class="info">Welcome to .......<br>text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text</div>

 

If news_items.php doesn't contain any PHP you can use $contents = file_get_contents("news_item.php"); and it will assign the contents of news_item.php to $contents.

 

edit: I still don't understand what you're trying to do really...

My 'news_items.php' file contains:

<div class="date">June 28, 2007</div>
<div class="info">Welcome to .......<br>text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text</div>

 

If news_items.php doesn't contain any PHP you can use $contents = file_get_contents("news_item.php"); and it will assign the contents of news_item.php to $contents.

 

edit: I still don't understand what you're trying to do really...

 

Cheers mate. Your my hero. Thats exactly what i was looking for.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.