goocharlton Posted July 13, 2007 Share Posted July 13, 2007 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 More sharing options...
infid3l Posted July 13, 2007 Share Posted July 13, 2007 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 https://forums.phpfreaks.com/topic/59798-solved-variable-running-when-it-shouldnt/#findComment-297314 Share on other sites More sharing options...
goocharlton Posted July 13, 2007 Author Share Posted July 13, 2007 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 https://forums.phpfreaks.com/topic/59798-solved-variable-running-when-it-shouldnt/#findComment-297326 Share on other sites More sharing options...
jitesh Posted July 13, 2007 Share Posted July 13, 2007 include means a file contains with line of codes. Link to comment https://forums.phpfreaks.com/topic/59798-solved-variable-running-when-it-shouldnt/#findComment-297335 Share on other sites More sharing options...
goocharlton Posted July 13, 2007 Author Share Posted July 13, 2007 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 https://forums.phpfreaks.com/topic/59798-solved-variable-running-when-it-shouldnt/#findComment-297336 Share on other sites More sharing options...
goocharlton Posted July 13, 2007 Author Share Posted July 13, 2007 include means a file contains with line of codes. Ok. So I must be using the wrong code then. What code do I use to call the variable from another file. Link to comment https://forums.phpfreaks.com/topic/59798-solved-variable-running-when-it-shouldnt/#findComment-297339 Share on other sites More sharing options...
infid3l Posted July 13, 2007 Share Posted July 13, 2007 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 https://forums.phpfreaks.com/topic/59798-solved-variable-running-when-it-shouldnt/#findComment-297341 Share on other sites More sharing options...
jitesh Posted July 13, 2007 Share Posted July 13, 2007 The variables you have mention at top are accessible in inculded files in same page. Link to comment https://forums.phpfreaks.com/topic/59798-solved-variable-running-when-it-shouldnt/#findComment-297343 Share on other sites More sharing options...
goocharlton Posted July 13, 2007 Author Share Posted July 13, 2007 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 https://forums.phpfreaks.com/topic/59798-solved-variable-running-when-it-shouldnt/#findComment-297344 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.