Gossamer Forum
Quote Reply
Ugghh PHP Good Perl Bad
Well, maybe not, but I am an idiot when it comes to perl and cgi.

I will pay you for this. By the way, the Globals listed in Support for attachments DO NOT WORK.

All that I want to do is have a global that will:

SELECT lsql_Links_Files.ID FROM lsql_Links, lsql_Links_Files WHERE lsql_Links_Files.ForeignColKey = lsql_Links.ID and lsql_Links.ID = <%ID%>

Join 2 tables and find return the LINKS_FILES ID for the corresponding link ID WHERE the <%ID%> is the current link. This way I can display the IMAGE that users upload.

Links SQL 2.2. Please don't just link to other posts. I have been all over this forum and the Globals do not work for what I want to do.

Ultimate goal : <img src=".../images/<%thisglobal'sreturnedvalue%>-filename.gif">

Where filename.gif is stored in the links table and the only variable number is that darn foreign key!!!

I want this to be static.

Thanks.
Quote Reply
Re: [mddrew01] Ugghh PHP Good Perl Bad In reply to
Hi,

Please try this. If that still does not work, just let me know

Code:
sub {
## usage:
##<%this_global('Logo')%>
## note that to pass the field name, not value
## if your actual upload directory is different just the the 'upload' in the return url
## below is presumed that your image dir is "$CFG->{build_root_path}/upload/"
my $field = shift;
my $tags = GT::Template->tags;
my $id = $tags->{ID};
if ($tags->{$field})
{

my $links_db = $DB->table(\'Links\');
my $fh = $links_db->file_info( "$field", $id );
return "" unless($fh);

my $location = $fh->File_RelativePath;


return qq~$CFG->{build_root_url}/upload$location~;
}
else
{
return "";
}
}

Cheers,

Dat

Programming and creating plugins and templates
Blog
Quote Reply
Re: [mddrew01] Ugghh PHP Good Perl Bad In reply to
Thanks! I am getting one small error.

Missing right curly or square bracket at (eval 51) line 2, at end of line syntax error at (eval 51) line 2, at EOF
Quote Reply
Re: [mddrew01] Ugghh PHP Good Perl Bad In reply to
Hi,

Make sure that you have copied the last '}'. It works for me.

Cheers,

Dat

Programming and creating plugins and templates
Blog
Quote Reply
Re: [mddrew01] Ugghh PHP Good Perl Bad In reply to
I do appreciate your help. Unfortunately, I have double checked your code and I still get the same error. I am placing <%upload%> in my links template. With your code, should I be implementing it differently? This is for Links 2.0.
Quote Reply
Re: [mddrew01] Ugghh PHP Good Perl Bad In reply to
In Reply To:
I do appreciate your help. Unfortunately, I have double checked your code and I still get the same error. I am placing <%upload%> in my links template. With your code, should I be implementing it differently? This is for Links 2.0.

This is not Links 2.0 forum
Quote Reply
Re: [mddrew01] Ugghh PHP Good Perl Bad In reply to
This should work =)

Code:
sub {
# -------------------------------------------------------------------
# Call with <%global_name($ID,'FieldName')%>
# NOTE: This is for the CATEGORY images...

my ($ID,$field,$table) = @_;

$table ||= 'Links';

# make sure a fieldname and ID are provided...
if (!$ID || !$field) { return "You need to define the ID and fieldname."; }

# get the actual path to where the file is/will be saved...
my $schema = $DB->table($table)->cols;
my $path = $schema->{$field}->{'file_save_url'};
$path =~ s,/$,,; # get rid of trailing / at end of $path

my $image_details = $DB->table($table."_Files")->select( { ForeignColName => $field, ForeignColKey => $ID } )->fetchrow_hashref;

my $id = $image_details->{ID};
my $filename = $image_details->{File_Name};
my $file_url = $image_details->{File_URL}; # this is only the URL/folder

my @cut = split //, $id;
my $folderid = $cut[$#cut];

my $url = "$file_url/$folderid/$id-$filename";


$url =~ s|([^\/]+)$|GT::CGI->escape( $1 )|e;

return $url;

}

Call with:

<%global_name($ID,'Field_Name','Table')%>

Smile

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!