Gossamer Forum
Quote Reply
Help making global
Hi,

Trying to turn the following into a global so I can put the payments_amount next to each listing in link.html:

SELECT payments_amount FROM lsql_Payments WHERE payments_linkid like '288' ORDER BY payments_amount

I realize the payments_linkid and the ID of the link are the same, can anyone lead me in the right direction to having a working global.

Thanks in advance...
Quote Reply
Re: [rascal] Help making global In reply to
Code:
sub {
my $table = $DB->table('Payments');
my $cond = GT::SQL::Condition->new(payments_linkid => 'LIKE' => $_[0]);
$table->select_options("ORDER BY payments_amount");
return $table->select('payments_amount' => $cond)->fetchrow;
}

Something like that I guess.
Quote Reply
Re: [Hargreaves] Help making global In reply to
Hi,

Not nit-picking, but... that will probably give an error; (didn't test it, but from previous globals, where I left this out by mistake, it gave syntax errors);

Code:
return $table->select('payments_amount' => $cond)->fetchrow;

...should be wrapped with { }

Code:
return $table->select( { 'payments_amount' => $cond } )->fetchrow;


Also, you need to specify what to grab.. i.e;

Code:
return $table->select( ['payments_amount'] , { 'payments_amount' => $cond } )->fetchrow;


Actually.. thinking about it, this may be better;


Code:
sub {
my $table = $DB->table('Payments');
$table->select_options("ORDER BY payments_amount","LIMIT 1");
return $table->select( ['payments_amount'] , { payments_linkid => $_[0] } )->fetchrow;
}

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!

Last edited by:

Andy: Dec 7, 2005, 10:06 AM
Quote Reply
Re: [Andy] Help making global In reply to
Quote:
Not nit-picking, but... that will probably give an error; (didn't test it, but from previous globals, where I left this out by mistake, it gave syntax errors);

It will work.

Quote:
...should be wrapped with { }

Nope - it gets treated the same way.

Quote:
Also, you need to specify what to grab.. i.e;

Already did :)

'payments_amount' => $cond
Quote Reply
Re: [Hargreaves] Help making global In reply to
Ooh.. that must be a new feature then. Just tried it, and it does work. You learn something new every day Tongue

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] Help making global In reply to
Code:
return $table->select( ['payments_amount'] , { 'payments_amount' => $cond } )->fetchrow;
Passing the wanted columns in as an array reference works, but is the old way (like many years old) of doing things, just pass it in as arguments to select() (it just looks nicer). $cond is a GT::SQL::Condition object, so that's why it works.

Adrian
Quote Reply
Re: [brewt] Help making global In reply to
Thanks to all of you for helping me out.
Quote Reply
Re: [brewt] Help making global In reply to
In Reply To:
Code:
return $table->select( ['payments_amount'] , { 'payments_amount' => $cond } )->fetchrow;
Passing the wanted columns in as an array reference works, but is the old way (like many years old) of doing things, just pass it in as arguments to select() (it just looks nicer). $cond is a GT::SQL::Condition object, so that's why it works.
Ah, so the way I'm doing it is right, or the dated version? Tongue

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] Help making global In reply to
dated. What I quoted won't work at all, since $cond is a condition object.

Adrian
Quote Reply
Re: [brewt] Help making global In reply to
Ah, ok <G>

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!