Jump to content

include() statement inside a for loop - aint working...


elias

Recommended Posts

 

Hi guys and gals!

 

I have various pages with slightly different code inside a for() loop:

 

		for ($i = 0; $i < $sn; $i = $i + 1){//first loop...			
			$detailsp = array();           
            			$detailsp = explode(" ", $lines[$xn]);
             //lots of code here.....
                        }

 

		for ($i = 0; $i < $sn; $i = $i + 1){	//first loop...
			$detailsp = array(); ;          
            			$detailsp = explode(" ", $lines[$xn]);
			$dummy2 = array_shift($detailsp);
             //lots of code here.....
                        }

 

I would like to just make one page with an include() statement to "include" the part of the code that changes.

 

		include 'compGlob_chnk1.txt' ;
             //lots of code here.....
                        }

 

where: compGlob_chnk1.txt, contains:

 

<?php


		for ($i = 0; $i < $sn; $i = $i + 1){	//first loop...		
			$detailsp = array();           
            			$detailsp = explode(" ", $lines[$xn]);		

?>

 

but I get an error, it seems the code "included" is not parsed as part of the for loop.

 

any help greatfully welcome :-)

 

cheers!!

 

elias

Link to comment
Share on other sites

Thanks guys

 

khr2003: if that is the case, that you cannot include "parts of a for loop", then the application of include() here is worthless, as the for loop is 446 lines, and the point of the exercise was that as 400 of the 446 lines where common, I would have only like a "header" included depending on which application I needed.

 

so, is there another neat way of achieving the same effect?:

 

I have three or more pages of code, where, say 40 lines are page specific (and contain the beginnings of teh for loop) and 400 are common (html tables showing the results, etc). How can I use the same page for the three pages, where an if() statement sorts out which code-header I need.

 

I am not sure if that was clear - I hope so.

 

TIA

 

elias

Link to comment
Share on other sites

It's quite difficult to see exactly what your objective is. To my knowledge, the only real requirement is that the opening curly bracket and the closing curly bracket of a language construct are in the same file. So you could possibly do something like this...

 

File1.php

<?
for($i = 1; $i < 10; $i++){
include('File2.php');
}
?>

 

But I'm assuming your saying that in your case this isn't suitable?

 

File2.php

echo $i;
// or whatever code you want here

 

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.