Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Conditional table select in LSQL Coding

Quote Reply
Conditional table select in LSQL Coding
Hi, I was wondering how can I do a conditional table select?

Here's the current code...

Code:
my $Date = "$year-$month-$day"; my $table = $DB->table('Links','CatLinks');
my $sth = $table->select( { Live_Date => "$Date" },{ CategoryID => '7' } ,{ CategoryID => '7' } ); my $LinkID;
while (my $hit = $sth->fetchrow_hashref) {
$LinkID = $hit->{ID};
}
What I want to do is change the red line so that $sth contains EITHER the pointer to the row with
the corresponding live date OR if it doesn't exist, select a random ROW.


E.g.

my $sth;
IF (Live_Date => "$Date") DOESN'T EXIST/MATCH)
$sth = $table->select ({RANDOM ROW FROM CATEGORY 7))
ELSE {
$sth = $table->select( { Live_Date => "$Date" },{ CategoryID => '7' } ,{ CategoryID => '7' } );
}

Does anybody know the syntax for the 4 lines above of pseudocode? I imagine the major issue is how to do the match.

Basically, the question is probably even simpler.
What does a $table->select command return if there is no match Smile
Subject Author Views Date
Thread Conditional table select in LSQL Coding scorpioncapital 4686 Nov 26, 2004, 1:22 PM
Thread Re: [scorpioncapital] Conditional table select in LSQL Coding
Andy 4589 Nov 26, 2004, 11:56 PM
Post Re: [Andy] Conditional table select in LSQL Coding
scorpioncapital 4573 Nov 27, 2004, 7:46 AM
Thread Re: [Andy] Conditional table select in LSQL Coding
scorpioncapital 4556 Nov 27, 2004, 7:54 AM
Thread Re: [scorpioncapital] Conditional table select in LSQL Coding
scorpioncapital 4565 Nov 27, 2004, 7:57 AM
Thread Re: [scorpioncapital] Conditional table select in LSQL Coding
Andy 4570 Nov 27, 2004, 8:03 AM
Thread Re: [Andy] Conditional table select in LSQL Coding
scorpioncapital 4571 Nov 27, 2004, 8:11 AM
Thread Re: [scorpioncapital] Conditional table select in LSQL Coding
scorpioncapital 4589 Nov 29, 2004, 10:39 AM
Post Re: [scorpioncapital] Conditional table select in LSQL Coding
scorpioncapital 4527 Nov 29, 2004, 10:51 AM