[SOLVED] please help - include ()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jrd
Forum Commoner
Posts: 53
Joined: Tue Mar 14, 2006 1:30 am

[SOLVED] please help - include ()

Post 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.
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post 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.
matthijs
DevNet Master
Posts: 3360
Joined: Thu Oct 06, 2005 3:57 pm

Post 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..]
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

Indeed you do! I editted mine 3 times aswell :P
matthijs
DevNet Master
Posts: 3360
Joined: Thu Oct 06, 2005 3:57 pm

Post 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 :? :)
jrd
Forum Commoner
Posts: 53
Joined: Tue Mar 14, 2006 1:30 am

Post 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 ==========

.
mickd
Forum Contributor
Posts: 397
Joined: Tue Jun 21, 2005 9:05 am
Location: Australia

Post by mickd »

It shouldn't make any difference whether you use print or echo.
jrd
Forum Commoner
Posts: 53
Joined: Tue Mar 14, 2006 1:30 am

Post by jrd »

yea, my mistake was the variable names.
Post Reply