getting pic info from pid getting pic info from pid
 

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

getting pic info from pid

Started by grantson, June 24, 2010, 11:59:44 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

grantson

Been reading the documentation & searching the board and through the core files all morning trying to find out how the array $Current_pic_data is populated

If i pass the pid in a url to another page within my site how do i then use the pid to gather the rest of the pic info



grantson


Αndré

Quote from: grantson on June 24, 2010, 11:59:44 AM
If i pass the pid in a url to another page within my site how do i then use the pid to gather the rest of the pic info
With a simple SQL query like
SELECT * FROM cpg15x_pictures WHERE pid = $pid

grantson

yes but how do I construct the database query the sql statement goes into

i assume there are functions within the include files which query the db meaning i dont need to set up the database connection from scratch

Αndré

/**
* cpg_db_connect()
*
* Connect to the database
**/

function cpg_db_connect()
{
   global $CONFIG;

   $result = @mysql_connect($CONFIG['dbserver'], $CONFIG['dbuser'], $CONFIG['dbpass']);

   if (!$result) {
       return false;
   }

   if (!mysql_select_db($CONFIG['dbname'])) {
       return false;
   }

   return $result;
}


The database settings are stored in include/config.inc.php.

grantson

not quite what i meant but a nudge in the right direction thanks andre


$result= cpg_db_query("SELECT `pid`, `filepath`, `filename`, `title`, `caption`, `keywords` FROM {$CONFIG['TABLE_PICTURES']}  WHERE pid='$pid'");
$PIC_DATA = mysql_fetch_array($result) or die(mysql_error());


but when i load the page after adding the query nothing happens,
no errors, no visable page source just a completly blank page

Αndré

Hard to say what went wrong, if you past only that code snippet.

I don't know how cpg_db_query is set in your code.
I don't know how $CONFIG['TABLE_PICTURES'] is set in your code.
I don't know how $pid is set in your code.
I don't know if a connection to the database already exists.

I don't know why you don't want to establish the database connection with standard PHP functions.

grantson

Quote from: Αndré on June 24, 2010, 03:26:04 PM
I don't know why you don't want to establish the database connection with standard PHP functions.

Sorry i think i am confusing both of us here

I have a link to a page in www.mysite.com/gallery/metapage.php?pid=x

when metapage.php loads i want to get the pid from the url then use the functions defined in the copermine include files as they are in other pages

<?php

define
('IN_COPPERMINE'true);

require(
'include/init.inc.php');

$pid$_GET['pid'];

$resultcpg_db_query("SELECT `pid`, `filepath`, `filename`, `title`, `caption`, `keywords` FROM {$CONFIG['TABLE_PICTURES']} WHERE pid='$pid'");
$PIC_DATA mysql_fetch_assoc($result) or die(mysql_error());

$PIC_DATA['url']="{$CONFIG['site_url']}albums{$PIC_DATA['filepath']}{$PIC_DATA['filename']}";

$pgTitle="{$PIC_DATA['title']}";
$pgDesc="blah";
$thumbUrl str_replace('normal''thumb'$PIC_DATA['url']);
$redirectUrl="{$CONFIG['site_url']}displayimage.php?pid={PIC_DATA['pid']}";
?>


as i say I was originally hoping there was a function somewhere in the function list that populated the array $current_pic_data[] which is used in displayimage.php etc but have been unable to find it

Αndré


grantson

Thanks Andre, after the initial confusion its now all working

final code looks something like this

<?php

define
('IN_COPPERMINE'true);

require(
'include/init.inc.php');

$pid $superCage->get->getInt('pid');

$resultcpg_db_query("SELECT `pid`, `filepath`, `filename`, `title`, `caption`, `keywords` FROM {$CONFIG['TABLE_PICTURES']} WHERE pid='$pid'");
$PIC_INFO mysql_fetch_assoc($result);
mysql_free_result($result);

$pgTitle="{$PIC_INFO['title']}";
$pgDesc="";
$PIC_INFO['url']="{$CONFIG['site_url']}albums/{$PIC_INFO['filepath']}{$PIC_INFO['filename']}";
$PIC_INFO['thumburl'] = "{$CONFIG['site_url']}albums/{$PIC_INFO['filepath']}thumb_{$PIC_INFO['filename']}";
$PIC_INFO['redirectUrl'] ="{$CONFIG['site_url']}displayimage.php?pid={$PIC_INFO['pid']}";
?>



Joachim Müller

For security reasons I'd change the query to something like$result = cpg_db_query("SELECT pid, filepath, filename, title, caption, keywords, pwidth, pheight FROM {$CONFIG['TABLE_PICTURES']} AS p WHERE pid='$pid' $FORBIDDEN_SET LIMIT 1");

grantson