Advanced search  

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]

Pages: [1]   Go Down

Author Topic: How To display text if no image present?  (Read 11768 times)

0 Members and 1 Guest are viewing this topic.

Stewwake

  • Coppermine newbie
  • Offline Offline
  • Posts: 18
How To display text if no image present?
« 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.


Logged

just_some_guy

  • Supporter
  • Coppermine addict
  • ****
  • Offline Offline
  • Posts: 539
  • I am currently on holiday, back in a few weeks. :D
Re: How To display text if no image present?
« Reply #1 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?
Logged
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

  • Coppermine newbie
  • Offline Offline
  • Posts: 18
Re: How To display text if no image present?
« Reply #2 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



Logged

just_some_guy

  • Supporter
  • Coppermine addict
  • ****
  • Offline Offline
  • Posts: 539
  • I am currently on holiday, back in a few weeks. :D
Re: How To display text if no image present?
« Reply #3 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.
Logged
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

  • Guest
Re: How To display text if no image present?
« Reply #4 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.
Logged

Stewwake

  • Coppermine newbie
  • Offline Offline
  • Posts: 18
Re: How To display text if no image present?
« Reply #5 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?


Logged

Stewwake

  • Coppermine newbie
  • Offline Offline
  • Posts: 18
Re: How To display text if no image present?
« Reply #6 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.


Logged

Stewwake

  • Coppermine newbie
  • Offline Offline
  • Posts: 18
Re: How To display text if no image present?
« Reply #7 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
Logged

Nibbler

  • Guest
Re: How To display text if no image present?
« Reply #8 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();

?>

Logged

Stewwake

  • Coppermine newbie
  • Offline Offline
  • Posts: 18
Re: How To display text if no image present?
« Reply #9 on: January 31, 2008, 11:11:11 pm »

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

Cheers.
Logged
Pages: [1]   Go Up
 

Page created in 0.022 seconds with 20 queries.