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
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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.