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: setReturnType resultset  (Read 5021 times)

0 Members and 1 Guest are viewing this topic.

Steve-R

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 38
setReturnType resultset
« on: January 24, 2008, 09:34:09 pm »

setReturnType resultset

Using the following code I have managed to display the array straight after it


Code: [Select]
<?php    

  
include_once "./cpmfetch/cpmfetch.php";
  
$objCpm = new cpm("./cpmfetch/cpmfetch_config.php");
  
$options = array( "<hr />""noimage" => "");
  
$objCpm->cpm_setReturnType("resultset");
  
$table $objCpm->cpm_viewTopRatedMediaFrom ("cat=1",100,1,$options);
  
print_r($table) ;
  
$objCpm->cpm_close();

?

Produces:

Code: [Select]
Array ( [0] => Array ( [pFilepath] => userpics/10004/ [pFilename] => Autumn_morning.jpg [pAid] => 3 [pFilesize] => 204624 [pTitle] => Autumn morning [pCaption] => The field opposite my home [pOwner_name] => Mike Young [pOwnerId] => 4 [pCtime] => 1193671357 [pHits] => 2 [pPid] => 7 [pPic_Rating] => 100000 [pVotes] => 100 [pWidth] => 1000 [pHeight] => 731 [pUser1] => [pUser2] => [pUser3] => [pUser4] => [cCid] => [cName] => [cDescription] => [cPos] => [cParent] => [cThumb] => [aAid] => 3 [aTitle] => Mikes bits and bobs [aDescription] => [aVisibility] => 0 [aPos] => 1 [aCategory] => 10004 [aThumb] => 0 [aKeyword] => [fullPathToThumb] => albums/userpics/10004/thumb_Autumn_morning.jpg [fullPathToNormal] => albums/userpics/10004/normal_Autumn_morning.jpg [fullPathToFull] => albums/userpics/10004/Autumn_morning.jpg [cpmSubtitle] => Autumn morning
by Mike Young

I want to be able to use this array, grab some of the values and insert into another database table for further usage, only I'm having trouble grabbing the values. I've read up on arrays and it appears that they are seperated by '' or `` but the array above uses [].

So in the new file below I have insert into table, field is "filetype" and value is pFiletype which does not work, so I also tried pFiletype and filetype and even [pFiletype], but these do not work either. I'm obviously missing something about manipulating arrays...as I dont think resultset would have been written by Vuud for no reason

Code: [Select]
<?php    
define
('IN_COPPERMINE'true);
require(
'include/init.inc.php');

  include_once 
"./cpmfetch/cpmfetch.php";
  
$objCpm = new cpm("./cpmfetch/cpmfetch_config.php");
  
$options = array( "<hr />""noimage" => "");
  
$objCpm->cpm_setReturnType("resultset");
  
$table $objCpm->cpm_viewTopRatedMediaFrom ("cat=1",100,1,$options);
  
print_r($table) ;
  
$objCpm->cpm_close();

  
$sql "INSERT INTO {$CONFIG['TABLE_TEST']} ".
         
"(filepath, filename) ".
         
"VALUES ('pFilepath', 'pFilename')";
  
$result cpg_db_query($sql)

?

How can I grab certain parts of this array and insert them into a new database table?

Thanks in advance

Steve...:)
« Last Edit: January 27, 2008, 02:35:49 pm by Nibbler »
Logged

Nibbler

  • Guest
Re: setReturnType resultset
« Reply #1 on: January 24, 2008, 09:58:01 pm »

Like this:

Code: [Select]

foreach ($table as $row){

  $sql = "INSERT INTO {$CONFIG['TABLE_TEST']} ".
         "(filepath, filename) ".
         "VALUES ('{$row['pFilepath']}', '{$row['pFilename']}')";

  cpg_db_query($sql);
}

Did you setup $CONFIG['TABLE_TEST'] in include/init.inc.php or is this just 'hit and hope' coding?
Logged

Steve-R

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 38
Re: setReturnType resultset
« Reply #2 on: January 27, 2008, 01:43:23 pm »

Like this:

Code: [Select]

foreach ($table as $row){

  $sql = "INSERT INTO {$CONFIG['TABLE_TEST']} ".
         "(filepath, filename) ".
         "VALUES ('{$row['pFilepath']}', '{$row['pFilename']}')";

  cpg_db_query($sql);
}

Did you setup $CONFIG['TABLE_TEST'] in include/init.inc.php or is this just 'hit and hope' coding?

A little bit of hit and hope, the last few queries I put together involved table pictures and table albums, so I copied the query again and changed to table test, knowing I could remove $CONFIG['TABLE_TEST'] and replace with the table name to make it work. However looking into /includes/init.inc.php I see where to add table test but that it also has a utf8 regex and a link to where to get more info in the comments. I dont ureally understand it so will just avoid adding to this for now and query the databse table without &config.

Can you tell me what advantage is gained from using &config?

Thanks for the code Nibbler, it worked a treat!! Can be marked as solved now.

Steve...:)
Logged

Nibbler

  • Guest
Re: setReturnType resultset
« Reply #3 on: January 27, 2008, 02:37:01 pm »

It means you can change the name of the table and use different prefixes without needing to change it all throughout the code.
Logged
Pages: [1]   Go Up
 

Page created in 0.028 seconds with 16 queries.