Gossamer Forum
Home : Products : Gossamer Links : Discussions :

if statement in global

Quote Reply
if statement in global
I use this global, and the if statment is never work even when there is a value to the uid.
Code:
sub {
use GT::SQL::Condition;
my $total = 0;
my $qqq = $_[2];
my $aaa = $_[3];
my $uid = $_[4];

my $tbl = $DB->table('FormDetails');
$tbl->select_options("ORDER BY ID DESC Limit $qqq, $aaa");
my $cond = new GT::SQL::Condition;
my $cond = GT::SQL::Condition->new($_[0] => $_[1]);
my $cond2 = new GT::SQL::Condition;

if ($uid)
{
my $cond2 = GT::SQL::Condition->new( Username => $_[4]);}

my $sth = $tbl->select( $cond, $cond2 ) || return $GT::SQL::error;
$total = $tbl->hits;

my @back;
while (my $hit = $sth->fetchrow_hashref) {
push @back, $hit;
} my $exists; if ($back[0]) { $exists = 1; } else { $exists = ''; }
return { lead_loop => \@back, link_count => $total} }
Quote Reply
Re: [nir] if statement in global In reply to
Hi,

You are re-defining $cond2 INSIDE the if () { } statement... so it doesn't exist when you make the call :) I've tidied the global up, and removed bits that are not being used:

Code:
sub {
use GT::SQL::Condition;
my $total = 0;
my $qqq = $_[2];
my $aaa = $_[3];
my $uid = $_[4];

my $tbl = $DB->table('FormDetails');
$tbl->select_options("ORDER BY ID DESC Limit $qqq, $aaa");

my $cond = GT::SQL::Condition->new($_[0] => $_[1]);
my $cond2 = new GT::SQL::Condition;

if ($uid) {
$cond2->add('Username','=',$_[4]);
}
my $sth = $tbl->select( $cond, $cond2 ) || return $GT::SQL::error;
my @back;
while (my $hit = $sth->fetchrow_hashref) {
push @back, $hit;
}

return { lead_loop => \@back, link_count => int @back }
}

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!