Hi, I was wondering how can I do a conditional table select?
Here's the current code...
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
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};
}
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
