I am having real trouble here getting this to work :( I need to use the OR option, so I can select from Multiple categories...BUT, I need the Live_Date and isValidated to also equal their respective values. The code I am using is;
my $date_ = GT::Date::date_get();
my $date1 = GT::Date::date_sub($date_,1);
my $date2 = GT::Date::date_sub($date_,2);
my $date3 = GT::Date::date_sub($date_,3);
my $date4 = GT::Date::date_sub($date_,4);
my $date5 = GT::Date::date_sub($date_,5);
my $date6 = GT::Date::date_sub($date_,6);
my $date7 = GT::Date::date_sub($date_,7);
# setup DB connections...
my $db_con = $DB->table("CatLinks","Links");
my $cond = GT::SQL::Condition->new(
'CategoryID', '=', '2',
'CategoryID', '=', '16',
'CategoryID', '=', '23',
'CategoryID', '=', '24',
'CategoryID', '=', '25',
'CategoryID', '=', '26',
'CategoryID', '=', '28',
'CategoryID', '=', '30',
'CategoryID', '=', '31',
'CategoryID', '=', '32',
'CategoryID', '=', '33',
'CategoryID', '=', '34',
'CategoryID', '=', '35',
'CategoryID', '=', '36',
'CategoryID', '=', '37',
'Live_Date' ,'=', $date1,
'Live_Date' ,'=', $date2,
'Live_Date' ,'=', $date3,
'Live_Date' ,'=', $date4,
'Live_Date' ,'=', $date5,
'Live_Date' ,'=', $date6,
'Live_Date' ,'=', $date7,
'isValidated' ,'=', 'Yes'
);
$cond->bool('or');
$db_con->select_options ('ORDER BY Rating DESC','LIMIT 1');
my $sth = $db_con->select( $cond );
while (my $hit = $sth->fetchrow_hashref) {
print "ID: " . $hit->{ID} . "<BR>";
}
Which translates to (from DEBUG output);
FROM lsql_CatLinks, lsql_Links
WHERE lsql_CatLinks.LinkID = lsql_Links.ID AND (lsql_CatLinks.CategoryID = '2' or lsql_CatLinks.CategoryID = '16' or lsql_CatLinks.CategoryID = '23' or lsql_CatLinks.CategoryID = '24' or lsql_CatLinks.CategoryID = '25' or lsql_CatLinks.CategoryID = '26' or lsql_CatLinks.CategoryID = '28' or lsql_CatLinks.CategoryID = '30' or lsql_CatLinks.CategoryID = '31' or lsql_CatLinks.CategoryID = '32' or lsql_CatLinks.CategoryID = '33' or lsql_CatLinks.CategoryID = '34' or lsql_CatLinks.CategoryID = '35' or lsql_CatLinks.CategoryID = '36' or lsql_CatLinks.CategoryID = '37' or
lsql_Links.Live_Date = '2003-09-19' or lsql_Links.Live_Date = '2003-09-18' or lsql_Links.Live_Date = '2003-09-17' or lsql_Links.Live_Date = '2003-09-16' or lsql_Links.Live_Date = '2003-09-15' or lsql_Links.Live_Date = '2003-09-14' or lsql_Links.Live_Date = '2003-09-13' or lsql_Links.isValidated = 'Yes')
ORDER BY Hits DESC LIMIT 1
As you can see, this won't work. it seems the isValidated part is picking up links that don't match the sql_Links.Live_Date or lsql_CatLinks.CategoryID value.
Anyone got an suggestions?
I'm totally stumped on this one.
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!
Code:
# figure out the date for this link... my $date_ = GT::Date::date_get();
my $date1 = GT::Date::date_sub($date_,1);
my $date2 = GT::Date::date_sub($date_,2);
my $date3 = GT::Date::date_sub($date_,3);
my $date4 = GT::Date::date_sub($date_,4);
my $date5 = GT::Date::date_sub($date_,5);
my $date6 = GT::Date::date_sub($date_,6);
my $date7 = GT::Date::date_sub($date_,7);
# setup DB connections...
my $db_con = $DB->table("CatLinks","Links");
my $cond = GT::SQL::Condition->new(
'CategoryID', '=', '2',
'CategoryID', '=', '16',
'CategoryID', '=', '23',
'CategoryID', '=', '24',
'CategoryID', '=', '25',
'CategoryID', '=', '26',
'CategoryID', '=', '28',
'CategoryID', '=', '30',
'CategoryID', '=', '31',
'CategoryID', '=', '32',
'CategoryID', '=', '33',
'CategoryID', '=', '34',
'CategoryID', '=', '35',
'CategoryID', '=', '36',
'CategoryID', '=', '37',
'Live_Date' ,'=', $date1,
'Live_Date' ,'=', $date2,
'Live_Date' ,'=', $date3,
'Live_Date' ,'=', $date4,
'Live_Date' ,'=', $date5,
'Live_Date' ,'=', $date6,
'Live_Date' ,'=', $date7,
'isValidated' ,'=', 'Yes'
);
$cond->bool('or');
$db_con->select_options ('ORDER BY Rating DESC','LIMIT 1');
my $sth = $db_con->select( $cond );
while (my $hit = $sth->fetchrow_hashref) {
print "ID: " . $hit->{ID} . "<BR>";
}
Which translates to (from DEBUG output);
Quote:
SELECT * FROM lsql_CatLinks, lsql_Links
WHERE lsql_CatLinks.LinkID = lsql_Links.ID AND (lsql_CatLinks.CategoryID = '2' or lsql_CatLinks.CategoryID = '16' or lsql_CatLinks.CategoryID = '23' or lsql_CatLinks.CategoryID = '24' or lsql_CatLinks.CategoryID = '25' or lsql_CatLinks.CategoryID = '26' or lsql_CatLinks.CategoryID = '28' or lsql_CatLinks.CategoryID = '30' or lsql_CatLinks.CategoryID = '31' or lsql_CatLinks.CategoryID = '32' or lsql_CatLinks.CategoryID = '33' or lsql_CatLinks.CategoryID = '34' or lsql_CatLinks.CategoryID = '35' or lsql_CatLinks.CategoryID = '36' or lsql_CatLinks.CategoryID = '37' or
lsql_Links.Live_Date = '2003-09-19' or lsql_Links.Live_Date = '2003-09-18' or lsql_Links.Live_Date = '2003-09-17' or lsql_Links.Live_Date = '2003-09-16' or lsql_Links.Live_Date = '2003-09-15' or lsql_Links.Live_Date = '2003-09-14' or lsql_Links.Live_Date = '2003-09-13' or lsql_Links.isValidated = 'Yes')
ORDER BY Hits DESC LIMIT 1
As you can see, this won't work. it seems the isValidated part is picking up links that don't match the sql_Links.Live_Date or lsql_CatLinks.CategoryID value.
Anyone got an suggestions?

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!