forum.coppermine-gallery.net

Support => cpg1.4.x Support => Older/other versions => cpg1.4 cpmFetch by vuud => Topic started by: El_Kevo on December 08, 2006, 08:38:59 am

Title: Problem with two cpmfetch codes on one site
Post by: El_Kevo on December 08, 2006, 08:38:59 am
Hi! i have a problem with cpmfetch!

i have this code on the left side of my page
Code: [Select]
<?php include("bilder_zufall.php"); ?>(for random pictures)
which is include this code:
Code: [Select]
<?php 
include "./cpmfetch/cpmfetch.php";
$objCpm = new cpm("/gallery");
$objCpm->cpm_viewRandomMedia(4,1);
$objCpm->cpm_close();
?>


and on the right side this code
Code: [Select]
<?php include("bilder_neu.php"); ?>(for new pictures)
which include this code:

Code: [Select]
<?php 
include "./cpmfetch/cpmfetch.php";
$objCpm = new cpm("/gallery");
$objCpm->cpm_viewLastAddedMedia(8,1);
$objCpm->cpm_close();
?>


now, i got this error message on the right side (where the new pictures from the gallery are)
Code: [Select]
Fatal error: Cannot redeclare class cpm in /home/www/web189/html/cpmfetch/cpmfetch.php on line 33

what's happen?! can't i put 2php codes on one side or what?!

if you want to see it, look at http://www.bratze-bunker.de/start.php

PS: soory for my bad english ;)
Title: Re: Problem with two cpmfetch codes on one site
Post by: Gizmo on December 08, 2006, 12:42:07 pm
Reading through the posts this morning having my coffee (OK, I'm a tea drinker...), I saw the similarities in this post with yours. Something about the include statement being added twice. Not sure but you can give it a try.
http://forum.coppermine-gallery.net/index.php?topic=39024.0 (http://forum.coppermine-gallery.net/index.php?topic=39024.0)
Title: Re: Problem with two cpmfetch codes on one site
Post by: Gizmo on December 08, 2006, 01:07:57 pm
OK... I'm the curious type and couldn't help giving this a try. :)  I set up my blog to have two images shown from two scripts and I got the same error as you. Then I removed this line from the second script and it worked fine.

Code: [Select]
include "./cpmfetch/cpmfetch.php";
I also remembered reading on Vuud's site that this only needs to be called once per page.
Title: Re: Problem with two cpmfetch codes on one site
Post by: El_Kevo on December 08, 2006, 01:13:27 pm
great man! thanks a lot!

you save my day ;)
Title: Re: Problem with two cpmfetch codes on one site
Post by: vuud on December 08, 2006, 03:52:14 pm
OK... I'm the curious type and couldn't help giving this a try. :)  I set up my blog to have two images shown from two scripts and I got the same error as you. Then I removed this line from the second script and it worked fine.

Code: [Select]
include "./cpmfetch/cpmfetch.php";
I also remembered reading on Vuud's site that this only needs to be called once per page.


Yep,

Just as a moving forward note, I am starting to advocate using include_once versus include - simply because there are more and more issues with this sort of thing coming up.  I believe include_once will not error out if it gets called a second time...  You could also use require_once, but I doubt someone would want the whole page going AWOL on a cpmfetch problem :)


Title: Re: Problem with two cpmfetch codes on one site
Post by: Gizmo on December 08, 2006, 04:01:14 pm
Good point! This way your individual php files are transferrable to other pages without having to edit them which I had to do this morning.
Title: Re: Problem with two cpmfetch codes on one site
Post by: niks_007 on December 19, 2006, 09:37:18 pm
Its very easy
dont close the object in first time only at the end of second time.

First time
Code: [Select]
<?php 
include "./cpmfetch/cpmfetch.php";
$objCpm = new cpm("/gallery");
$objCpm->cpm_viewRandomMedia(4,1);
?>

Second Time
Code: [Select]
<?php 
include "./cpmfetch/cpmfetch.php";
$objCpm = new cpm("/gallery");
$objCpm->cpm_viewLastAddedMedia(8,1);
$objCpm->cpm_close();
?>

Hope this can help.
Niks