Gossamer Forum
Quote Reply
What am I doing wrong?
Argh..this is a pain! I'm trying to write a global, so that an icon is only shown if the owner of the link, has their username set to 'isPro' in the links_Users table.

At the moment I have;

Code:
sub {

# check if a user is a pro...
my $check_user = shift;
print $check_user . "<BR>";
my $isPro;

my $table = $DB->table('Users');
my $sth = $table->select( { Username => $check_user } );

while (my $hit = $sth->fetchrow_hashref) {

$isPro = $hit->{isPro};

} # end while...

return $isPro;

}

For some reason, this is printing out;

HASH(0x86d155c)
admin
HASH(0x86a3a88)
admin
HASH(0x8706cf0)
admin

This is coming from print $check_user . "<BR>";, but the problem is that this HASH() thing keeps appearing Unsure I am using;

<%if check_pro($Username)%>
stuff here]
<%endif%>

to try call the global....can anyone see why it wont work? I've been fumbling over this for the last few hours.

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!
Quote Reply
Re: [Andy] What am I doing wrong? In reply to
I think this is because it is finding more than one record. I might be wrong though.

It seems awful complex just to check if a user has a value too.

Why not just a simpler select stament?

i.e. do the select, do a if ($table_handle->hits) on the table and return true if there is


http://www.iuni.com/...tware/web/index.html
Links Plugins

Last edited by:

Ian: Aug 20, 2002, 9:07 AM
Quote Reply
Re: [Andy] What am I doing wrong? In reply to
What about
Code:
sub {
return $DB->table('Users')->get($_[0])->{isPro};
}

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] What am I doing wrong? In reply to
Yes, exactly what I wanted to say LOL


http://www.iuni.com/...tware/web/index.html
Links Plugins
Quote Reply
Re: [Ian] What am I doing wrong? In reply to
Mmm..that is giving me an error;

A fatal error has occured:

Can't use an undefined value as a HASH reference at (eval 23) line 2.

Please enable debugging in setup for more details.

Unsure

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!
Quote Reply
Re: [yogi] What am I doing wrong? In reply to
Code:
sub {
my $user = $DB->table('Users')->get($_[0]);
$user and return $user->{isPro};
}

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [Andy] What am I doing wrong? In reply to
Never mind...I got it figured now ;)

Code:
sub {
my $user = shift;
return $DB->table('Users')->get($user[0])->{isPro};
}

Cheers for the help guys :)

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!
Quote Reply
Re: [Andy] What am I doing wrong? In reply to
Mmm...something weird going on here. I tried Yogi's sub, and now I am getting;

Unable to compile 'check_pro':

Using <%if check_pro($LinkOwner)%> works fine, but as soon as I try;

<%check_pro($LinkOwner%>

I get the error in the template. Any ideas? Unsure

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!
Quote Reply
Re: [Andy] What am I doing wrong? In reply to
Any ideas? Unsure

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!
Quote Reply
Re: [Andy] What am I doing wrong? In reply to
Missing )

?

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] What am I doing wrong? In reply to
Nope...I actually have: <%check_pro($LinkOwner)%> , the ) was just missing cos I typed the code in manually, rather than copying and pasting from the template Tongue

Why should it give that error? Does it mean there is a syntax error wrong with it, and if so, is there any way to find out what the syntax error is? Unsure

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!
Quote Reply
Re: [Andy] What am I doing wrong? In reply to
Finding errors in globals in not fun.

I ususally just write my globals in a small script that I can test (perl -c script.pl), when I am sure that it works, I copy/past the sub into a global....

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] What am I doing wrong? In reply to
Mmm...do you have a working global, in the form of a simple script, that I could have a look at? I'm having trouble working out how you would do it :(

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!
Quote Reply
Re: [Andy] What am I doing wrong? In reply to
Global developping for dummies, see attachment. You can test most of your globals with this construction (not the ones that you call without arguments, but that use the hashref of all template tags).

Ivan
-----
Iyengar Yoga Resources / GT Plugins

Last edited by:

yogi: Aug 21, 2002, 3:23 AM
Quote Reply
Re: [yogi] What am I doing wrong? In reply to
Cheers...thats great :) I'll give it a go now...

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!
Quote Reply
Re: [yogi] What am I doing wrong? In reply to
Ok...here we go;

sub {
my $user_in = shift;
my $user = $DB->table('Users')->get($user_in[0]);
$user and return $user->{isPro};
}

That code is reporting that @user_in must have be designated by a 'my'. I change the my $user_in = shift; to my @user_in = shift; , but that now gives me a 500 IS error on the whole page Unsure

At least we are getting somewhere Unsure

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!
Quote Reply
Re: [Andy] What am I doing wrong? In reply to
I'm not sure I understand the issues here, it should be a simple global. You should be checking your error log for errors.

Code:
sub {
my $ref = $DB->table('Users')->select( { Username => shift } )->fetchrow_hashref;
return ref $ref eq 'HASH' ? $ref->{isPro} : $GT::SQL::error;
}


Then just use <%MyTag($Username)%>

Last edited by:

PerlPod: Aug 21, 2002, 3:48 AM
Quote Reply
Re: [PerlPod] What am I doing wrong? In reply to
Cheers mate, worked great Smile

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!
Quote Reply
Re: [Andy] What am I doing wrong? In reply to
You might not want to use $GT::SQL::error for the real global, exchange it for a generic error message, I was just giving a wacky example.
Quote Reply
Re: [PerlPod] What am I doing wrong? In reply to
Mmm...this is weird. Just using;

<%check_pro($Username)%>, prints out '1', which is correct. However, if I put it in the form of;

<%if check_pro($Username)%>
something here
<%endif%>

It will not print out the 'something here', just returns false all the time Unsure

Does links SQL support if statements with globals in?

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!