setReturnType resultset setReturnType resultset
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

setReturnType resultset

Started by Steve-R, January 24, 2008, 09:34:09 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Steve-R

setReturnType resultset

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



<?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:


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


<?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...:)

Nibbler

Like this:



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?

Steve-R

Quote from: Nibbler on January 24, 2008, 09:58:01 PM
Like this:



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...:)

Nibbler

It means you can change the name of the table and use different prefixes without needing to change it all throughout the code.