How To display text if no image present? How To display text if no image present?
 

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Main Menu

How To display text if no image present?

Started by Stewwake, January 30, 2008, 01:37:24 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Stewwake

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.



just_some_guy

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?
Tambien, Hablo Español      PHP - Achieve Anything
"The Internet is becoming the town square for the global village of tomorrow. " - Bill Gates
Windows 7 Forums

Stewwake

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




just_some_guy

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.
Tambien, Hablo Español      PHP - Achieve Anything
"The Internet is becoming the town square for the global village of tomorrow. " - Bill Gates
Windows 7 Forums

Nibbler

Instead of guessing, see what it actually returns:


$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.

Stewwake

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?



Stewwake

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.



Stewwake

$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

Nibbler

The zero is not a return value, it is just printed by the function. Use the output buffer to catch the number.


<?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();

?>


Stewwake

Thanks for that Nibbler, I'll give that a go and post the result.

Cheers.