elias Posted September 29, 2009 Share Posted September 29, 2009 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 Quote Link to comment Share on other sites More sharing options...
jon23d Posted September 29, 2009 Share Posted September 29, 2009 What would that error be? Quote Link to comment Share on other sites More sharing options...
elias Posted September 29, 2009 Author Share Posted September 29, 2009 Parse error: parse error in C:\xampp\htdocs\xxxxxx\stats\admin\compGlob_form1.php on line 446 ...where line 446 is the closing "}" of the for loop Quote Link to comment Share on other sites More sharing options...
jon23d Posted September 29, 2009 Share Posted September 29, 2009 Can we see the whole block? Quote Link to comment Share on other sites More sharing options...
khr2003 Posted September 30, 2009 Share Posted September 30, 2009 my guess is that you have to include the whole for loop in the included page, you can not include the for loop without the closing bracket Quote Link to comment Share on other sites More sharing options...
elias Posted September 30, 2009 Author Share Posted September 30, 2009 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 Quote Link to comment Share on other sites More sharing options...
cags Posted September 30, 2009 Share Posted September 30, 2009 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.