Page 1 of 1

[SOLVED] please help - include ()

Posted: Thu Mar 16, 2006 2:08 am
by jrd
I have a few php files from which i have calculations being done in them before spitting out an output through 'echo'. I thought of using a few instances of

Code: Select all

include('filename')
to display the date in a master file, but the problem is the data becomes cumalative. For instance,

Sample Index.php

Code: Select all

<?php

$b155 = include_once('b155.php');	   
$b160 = include_once('b160.php');
$b165 = include_once('b165.php');
$b170 = include_once('b170.php');
$b175 = include_once('b175.php');
$b180 = include_once('b180.php');
$b185 = include_once('b185.php');
$b190 = include_once('b190.php');
				  
echo $b155;	   
echo $b160;
echo $b165;
echo $b170;
echo $b175;
echo $b180;
echo $b185;
echo $b190;

?>
Output fron index file.

Code: Select all

0 16 20 46 77 108 116 116 11111111
I thank you in advance and will thank you again if you can help me. Please....
Could someone pop me a substitute for include() which would allow me to display the data.

Posted: Thu Mar 16, 2006 3:12 am
by jayshields
What do the files your including contain?

I'm presuming its something like return 12 + 3 or something? I can't understand why you would want to do something like that in an include.

Since I don't know what's in the files, and I'm presuming it's a return statement to output the value, change the return statement to an echo, and then don't set/echo those variables at all.

I noticed you said date in your post, I presume you mistyped data? Anyway, I don't think you should/can set variables to include statements anyway, there's no need.

All include does is execute the code in the file in the parameter, read up on it @ php.net.

Posted: Thu Mar 16, 2006 3:17 am
by matthijs
Include is just for including one file in the other. So it has little to do with the way the data is outputted. That happens when you echo. It depends on what is inside the files you included what is finally echoed.

I think that if you show us what is inside the files we can help you further.

If the calculations in the different files use the same variables, it's possible that that's were the problem is.

[edit: I reeeally need to learn to type faster..]

Posted: Thu Mar 16, 2006 3:28 am
by jayshields
Indeed you do! I editted mine 3 times aswell :P

Posted: Thu Mar 16, 2006 5:16 am
by matthijs
jayshields wrote:Indeed you do! I editted mine 3 times aswell :P
yeah. and besides typing faster, some faster brain cpu would be nice as well :? :)

Posted: Thu Mar 16, 2006 6:26 pm
by jrd
Thanks Jayshields and Matthijs for your responses, i appreciate it. I've removed the echo, am using the "print" statement now.

Your assumptions were right. I used the same named "$total_output" in my other files. Even though they were in different files, because the variable had the same name, it was cumalating the total outputs. It's a pretty neat trick actually.


==========SOLVED ==========

.

Posted: Fri Mar 17, 2006 12:47 am
by mickd
It shouldn't make any difference whether you use print or echo.

Posted: Fri Mar 17, 2006 12:54 am
by jrd
yea, my mistake was the variable names.