Question before using (that I couldn't find in docs) Question before using (that I couldn't find in docs)
 

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

Question before using (that I couldn't find in docs)

Started by jw0ollard, November 27, 2007, 09:18:53 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

jw0ollard

Before downloading and installing I wanted to ask a fairly simple question:

How does cpmFetch handle empty results?... and can you specify a "fallback" function with a different search?

Meaning if I search for 1 image with keyword = X,  album = Y, and user = Z,  is there an easy way to use a different set of search terms as a fallback?  I'm getting OK with PHP, so I thought maybe changing one of the examples in the docs to something like this may work:

<?php
  
include_once "./cpg/cpmfetch/cpmfetch.php";
  
$objCpm = new cpm("./cpg/cpmfetch/cpmfetch_config.php");
  
$result1 $objCpm->cpm_viewLastAddedMedia("cat=5,3:album=10:owner=vuud",14);
  
$result2 $objCpm->cpm_viewRandomMediaFrom("cat=5,3:album=9:owner=vuud2",14);

  if(!empty(
$result1)){
    
$result1;
  }
  else{
    
$result2;
  }
  
$objCpm->cpm_close(); 
?>

(Pay no attention to the actual $source string in the example.. it's really just arbitrary. I basically just copy/pasted some things from the documentation, so I'm not really sure $result1 could ever be empty and $result2 would not, etc)

But since I don't know the code, I don't know if they can be assigned to variables like this without breaking?  I also don't know what it does without any results, so I'm not sure if "empty" will work in this case?  I assume it just doesn't print any output whatsoever, to keep it from breaking the page it's on, or displaying a bunch of PHP errors?

Also, is there any better, built-in way of doing this?  No matter what, I guess there would have to be at least 2 queries, or I should say 2 x (# of queries a normal function uses) since what I'm asking about requires the comparison of multiple searches.

I'd also REALLY wish I could ask more than one question as I don't want to flood the forum with separate threads.  Maybe I'll just wait until I first get an answer from this before asking any more.

Thank you.

jw0ollard

Can you only edit in certain forums here?  I know I've edited before.

Anyway,  I forgot to mention I'm not even sure that just typing $result1;  or $result2; in the if/else statements will even do anything. 

Should it be something like  "return $result1;" and "return $result2;" instead?

(I usually am really good at changing existing PHP, just not creating any of it!! :( haha)

vuud

Quote from: jw0ollard on November 27, 2007, 09:18:53 PM
Before downloading and installing I wanted to ask a fairly simple question:

How does cpmFetch handle empty results?... and can you specify a "fallback" function with a different search?

Meaning if I search for 1 image with keyword = X,  album = Y, and user = Z,  is there an easy way to use a different set of search terms as a fallback?  I'm getting OK with PHP, so I thought maybe changing one of the examples in the docs to something like this may work:

<?php
  
include_once "./cpg/cpmfetch/cpmfetch.php";
  
$objCpm = new cpm("./cpg/cpmfetch/cpmfetch_config.php");
  
$result1 $objCpm->cpm_viewLastAddedMedia("cat=5,3:album=10:owner=vuud",14);
  
$result2 $objCpm->cpm_viewRandomMediaFrom("cat=5,3:album=9:owner=vuud2",14);

  if(!empty(
$result1)){
    
$result1;
  }
  else{
    
$result2;
  }
  
$objCpm->cpm_close(); 
?>

(Pay no attention to the actual $source string in the example.. it's really just arbitrary. I basically just copy/pasted some things from the documentation, so I'm not really sure $result1 could ever be empty and $result2 would not, etc)

But since I don't know the code, I don't know if they can be assigned to variables like this without breaking?  I also don't know what it does without any results, so I'm not sure if "empty" will work in this case?  I assume it just doesn't print any output whatsoever, to keep it from breaking the page it's on, or displaying a bunch of PHP errors?

Also, is there any better, built-in way of doing this?  No matter what, I guess there would have to be at least 2 queries, or I should say 2 x (# of queries a normal function uses) since what I'm asking about requires the comparison of multiple searches.

I'd also REALLY wish I could ask more than one question as I don't want to flood the forum with separate threads.  Maybe I'll just wait until I first get an answer from this before asking any more.

Thank you.

I think you are heading down the right tracks with doing the if / else statements in your code.  CpmFetch does not have anything like that in the code itself.

One suggestion would be to nest the actual calls instead of running the CpmFetch stuff twice if you don't need too...

I think you would need to set it to return HTML and then check to see how many results you have.  I think there was something in there that you could call for the size of the SQL result set.  But I don't see it in the documentation - I will have to check the code.

EDIT:   You should be able to read

$objCPM->lastSQLRowsReturned;

This will return the number of rows returned from the last SQL call.  Now, if it does not work for you, it may only be in a newer unreleased version.  You can search the cpmfetch_dao.php for the "lastSQLRowsReturned"... if you find it, you should be good.














Please post for help to the forum... PM me only if you are sending security related items (passwords, security problems, etc).

cpmFetch - Images, RSS feeds from CPG from outside CPG
New release notification signup also. 
See http://cpmfetch.fistfullofco