forum.coppermine-gallery.net

Support => cpg1.4.x Support => Older/other versions => cpg1.4 cpmFetch by vuud => Topic started by: Stewwake on January 30, 2008, 01:37:24 am

Title: How To display text if no image present?
Post by: Stewwake on January 30, 2008, 01:37:24 am
Hi there, love cpmfetch a lot.

Apologies if this is a php question but have looked everywhere for an answer an tried multiple soloutions.

I am fetching images from a specific album, and I can do this fine.

What I'd like to be able to do is display text if no image is present in that album.

Am currently using this under the cpmFetch code :

<?php
  if ($objCpm === NULL) {echo "No image yet";
  }
?>

Any ideas? - not sure if there is a way to do this with the cpmFetch existing code, thanks Vuud or anyone who can help.


Title: Re: How To display text if no image present?
Post by: just_some_guy on January 30, 2008, 06:58:48 pm
I don't have cpmfetch but this is from a PHP programmer point of view,  the standard "equal to" symbol is "==" not "===", unless this changes in cpmfetch... What is $objCpm, are you counting something?
Title: Re: How To display text if no image present?
Post by: Stewwake on January 30, 2008, 08:09:23 pm
Hi there, thanks for the reply,

This is the cpmfetch code that I use to pull images from a certain album, in this case album #4:

<?php
  include_once "./gallery/cpmfetch/cpmfetch.php";
  $objCpm = new cpm("./gallery/cpmfetch/cpmfetch_config.php");
  $options = array("imagewidth" => "110", "imagestyle" => "albumimg",);
  $objCpm->cpm_viewLastAddedMediaFrom("album=4",2,2, $options);
  $objCpm->cpm_close();
?>

Now I if there is no image in the album, i.e. no image has been pulled through I want to display some text.
I was trying out the

if ($objCpm === NULL) but no luck - Im not sure if $objCpm is the right thing to query.

I also gave just double signs a go "==" but no luck either.

Any ideas? Thanks



Title: Re: How To display text if no image present?
Post by: just_some_guy on January 30, 2008, 08:33:30 pm
I'm not familiar with the cpmfetch code or how it goes about calling images etc. as i said earlier, perhaps try - equal to 0.
Title: Re: How To display text if no image present?
Post by: Nibbler on January 30, 2008, 08:59:24 pm
Instead of guessing, see what it actually returns:

Code: [Select]
$result = $objCpm->cpm_viewLastAddedMediaFrom("album=4",2,2, $options);
var_dump($result);

If that doesn't give you anything useful you could either add that feature to cpmfetch or collect the output in an output buffer and look for some string in the results.
Title: Re: How To display text if no image present?
Post by: Stewwake on January 30, 2008, 09:20:07 pm
Hi There, thanks both for reply,

tried "0" but didn't work.

Nibbler - I used your output code and the html page displayed as normal but in the place of an image gave 4 warnings, along the lines of "Warning: mysql_query(): 35 is not a valid MySQL-Link resource in /cpmfetch_dao.php on line 1240 ...etc... but one warning output a lot of variables, a few looked interesting:

WHERE 1 AND p.approved='YES' AND ( p.aid=4 ) AND ((a.visibility = 0 OR a.visibility IS NULL) AND (a.alb_password IS NULL OR a.alb_password = "")) ORDER BY p.ctime DESC LIMIT 0,4

Do you think I can use the "a.visibility" as a query?


Title: Re: How To display text if no image present?
Post by: Stewwake on January 30, 2008, 09:59:50 pm
Hi there,

Hmm, have tried a.visibilty but now realise that is album visibilty so was a bad suggestion on my behalf.

Am looking into an output buffer but have limited php knowledge, if anyone has any ideas that'd be great.


Title: Re: How To display text if no image present?
Post by: Stewwake on January 30, 2008, 10:52:45 pm
$options = array("imagewidth" => "110", "imagestyle" => "albumimg",);
  $objCpm->cpm_viewLastAddedMediaFrom("album=4",2,2, $options, array("imagestyle" => "test1"));
  $objCpm->cpm_listMediaCountForAlbum (4);

  if ($retval == 0) {echo "no image yet";}
 $objCpm->cpm_close();
?>

Have managed to pull with cpmfetch the total number of pics in the album: cpm_listMediaCountForAlbum

This then prints a zero on the page, have tried :  if ($objCpm->cpm_listMediaCountForAlbum (4) == 0) {echo "no image yet";}

But no luck,

and have tried:

 if ($retval == 0) {echo "no image yet";}

$retval being the variable from the cpmfetch config file.

Anyone spot the prob?

Thanks
Title: Re: How To display text if no image present?
Post by: Nibbler on January 30, 2008, 11:24:22 pm
The zero is not a return value, it is just printed by the function. Use the output buffer to catch the number.

Code: [Select]
<?php

include_once "./gallery/cpmfetch/cpmfetch.php";
$objCpm = new cpm("./gallery/cpmfetch/cpmfetch_config.php");

ob_start();
$objCpm->cpm_listMediaCountForAlbum (4); 
$number ob_get_clean();

if (
$number 0){
    
$options = array("imagewidth" => "110""imagestyle" => "albumimg",);
    
$objCpm->cpm_viewLastAddedMediaFrom("album=4",2,2$options);
} else {
    echo 
"Nothing to display";
}

$objCpm->cpm_close();

?>

Title: Re: How To display text if no image present?
Post by: Stewwake on January 31, 2008, 11:11:11 pm
Thanks for that Nibbler, I'll give that a go and post the result.

Cheers.