Gossamer Forum
Quote Reply
SQL by condition
Code:
my $sql="";
if ($dl > 25) {
$sql = ",'sorter','<','21'";
}

$all_db->select_options ("ORDER BY sorter, Contact_Name", "");
my $sth = $all_db->select ( ['LinkID','Title','URL','Links.Description','Contact_Name', 'sorter'],
GT::SQL::Condition->new ('isValidated','=','Yes',
'CategoryID','=',$catid
$sql
) );
while (my ($lid, $title, $url, $descr, $cname, $sorter) = $sth->fetchrow_array) {



I get an error, and i dont know why. It is not possible to insert $sql to the query?

Last edited by:

Robert: Jul 29, 2016, 3:57 AM
Quote Reply
Re: [Robert] SQL by condition In reply to
Got it:

Code:
my $cond = GT::SQL::Condition->new(
'CategoryID','=',$catid,
'isValidated','=','Yes',
);

if ($dl > 25) {
$cond->add('sorter','<','21');
}

my $sth = $all_db->select ( ['LinkID','Title','URL','Links.Description','Contact_Name', 'sorter'], $cond);
Quote Reply
Re: [Robert] SQL by condition In reply to
You're getting the hang of this Angelic

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!