php includes. NEED HELP

  • sazn
  • Student
  • Student
  • User avatar
  • Posts: 98

Post 3+ Months Ago

i'm pretty desperate to know weather you can have more than one php include on the same web page. i'm using a simple news management script (cutenews) and want to show two different things with it on the same page. when i put include("news/show_news.php"); on my page to show the news it works fine but if i put another one on the page thats diffrent such as include("news2/show_news.php"); then the second shows- Fatal error: Cannot redeclare formatsize() (previously declared in /home/gtaspot/public_html/news/inc/functions.inc.php:15) in home/gtaspot/public_html/news2/inc/functions.inc.php on line 15 in the place were the news should be? is what i'm trying to do not possible? if it is possible how can i do it?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • b_heyer
  • Web Master
  • Web Master
  • User avatar
  • Posts: 4581
  • Loc: Maryland

Post 3+ Months Ago

The problem is the file you are including is including another file with the same function as the previous one on it. What you might have to do is cut out the includes from the file and save it to a new name, then include that file in place of your second include. Do you have the source, or a place where we can have a look at it? Kind of hard to say exactly WHAT needs trimming.

Hope that helped.
  • sazn
  • Student
  • Student
  • User avatar
  • Posts: 98

Post 3+ Months Ago

did you mean the source of the page i am trying to display the 2 includes on or the source of the actual news script?

heres the part of my page were i have the two php includes

Code: [ Select ]
<div>
     <?PHP
include("gangsternews/show_news.php");
?>
    </div>
</div></td>
  </tr>
  <tr>
   <td background="mainbackbit.bmp" bgcolor="#FF9900"><div align="center">
    <?PHP
include("affmanger/show_news.php");
?>
   </div></td>
  1. <div>
  2.      <?PHP
  3. include("gangsternews/show_news.php");
  4. ?>
  5.     </div>
  6. </div></td>
  7.   </tr>
  8.   <tr>
  9.    <td background="mainbackbit.bmp" bgcolor="#FF9900"><div align="center">
  10.     <?PHP
  11. include("affmanger/show_news.php");
  12. ?>
  13.    </div></td>
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

sazn wrote:
did you mean the source of the page i am trying to display the 2 includes on or the source of the actual news script?

heres the part of my page were i have the two php includes

Code: [ Select ]
<div>
     <?PHP
include("gangsternews/show_news.php");
?>
    </div>
</div></td>
  </tr>
  <tr>
   <td background="mainbackbit.bmp" bgcolor="#FF9900"><div align="center">
    <?PHP
include("affmanger/show_news.php");
?>
   </div></td>
  1. <div>
  2.      <?PHP
  3. include("gangsternews/show_news.php");
  4. ?>
  5.     </div>
  6. </div></td>
  7.   </tr>
  8.   <tr>
  9.    <td background="mainbackbit.bmp" bgcolor="#FF9900"><div align="center">
  10.     <?PHP
  11. include("affmanger/show_news.php");
  12. ?>
  13.    </div></td>


The problem is that one of the include files conatin a function declaration for formatsize.

You need to take a look at your code and see how you can make the two include files into one. Or the easy way out would be to simply remove the function declarations from the two news include files because they will feed of the main include containing the function
  • sazn
  • Student
  • Student
  • User avatar
  • Posts: 98

Post 3+ Months Ago

sorry i'm very new to php, how would i remove the function declarations?
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

sazn wrote:
sorry i'm very new to php, how would i remove the function declarations?


Look for something that says
Code: [ Select ]
function formatsize(might be parameters){
// PHP Code
}
  1. function formatsize(might be parameters){
  2. // PHP Code
  3. }


don't remove this from the functions.inc.php file! remove it from the other two
  • b_heyer
  • Web Master
  • Web Master
  • User avatar
  • Posts: 4581
  • Loc: Maryland

Post 3+ Months Ago

what's happening is he is calling the exact same file twice.

Each file is calling the functions.inc.php file, thus it is called twice. Thus the formatsize function is getting declared twice.

All you have to do is look for:

Code: [ Select ]
include('functions.inc.php');


in affmanger/show_news.php and change to

Code: [ Select ]
//include('functions.inc.php');


Now the first include (the gangternews one) will call the functions you need for both, and any other includes you have.
  • Carnix
  • Guru
  • Guru
  • User avatar
  • Posts: 1098

Post 3+ Months Ago

you could also change the include directives all to include_once or require_once (I prefer require... but then, really, they're more or less the same). That way, if the same file is included anywhere else later in the script, that include directive will be ignored by PHP.

If you're using OO-style PHP, everything is functionalized anyway, so this shouldn't be a problem.. in fact, including a file twice will almost always cause an error if you're doing it the most efficient way possible....

.c
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

b_heyer wrote:
what's happening is he is calling the exact same file twice.


Ooops, was reading the sub directories it was coming from - missed the fact that it was the same file name :oops:

Post Information

  • Total Posts in this topic: 9 posts
  • Users browsing this forum: No registered users and 58 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.