To test if a variable returned from a database has a value or is defined do you go: if $LinkID == null or do you go if $LinkID = ""
Nov 20, 2004, 11:54 AM
User (150 posts)
Nov 20, 2004, 11:54 AM
Post #3 of 6
Views: 2218
my code is:
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};
}
my $details;
if ($LinkID) {
do this}
else {}
I guess I can always use the code:
if !($LinkID) {}
right?
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};
}
my $details;
if ($LinkID) {
do this}
else {}
I guess I can always use the code:
if !($LinkID) {}
right?
Nov 20, 2004, 12:12 PM
Veteran (1921 posts)
Nov 20, 2004, 12:12 PM
Post #4 of 6
Views: 2231
As far as I am aware if you have my $LinkID it is equivalent to my $LinkID = '';
So I think you should be able to use
if ($LinkID eq '') {...
or
if (!$LinkID) {...
or
unless ($LinkID) {...
Is there any reason why you have CategoryID => '7' twice? Think this line just needs to be this:
my $sth = $table->select( { Live_Date => "$Date", CategoryID => '7' } );
So I think you should be able to use
if ($LinkID eq '') {...
or
if (!$LinkID) {...
or
unless ($LinkID) {...
Is there any reason why you have CategoryID => '7' twice? Think this line just needs to be this:
my $sth = $table->select( { Live_Date => "$Date", CategoryID => '7' } );