Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^3: How's My Style Now?

by chb (Deacon)
on Feb 08, 2010 at 13:49 UTC ( [id://822006]=note: print w/replies, xml ) Need Help??


in reply to Re^2: How's My Style Now?
in thread How's My Style Now?

Just change your control flow slightly and prepare/execute the entire statement inside the if/elsif/else blocks (warning: untested code)
sub get_musings_entries { # get musings from MySQL my ($musing_id,$ref_id) = @_; if($ref_id && $ref_id eq 'all') { $sth = $dbh->prepare(qq|SELECT musing_id, ref_id, heading,abstract, DATE_FORMAT(entry_date, '%M %e, %Y') FROM musings ORDER BY entry_date DESC|); $sth->execute(); } elsif($ref_id) { $sth = $dbh->prepare(qq|SELECT musing_id, ref_id, heading, abstract, DATE_FORMAT(entry_date, '%M %e, %Y') FROM musings WHERE ref_id = '?' ORDER BY entry_date DESC LIMIT 10|); $sth->execute($ref_id); } else { $sth = $dbh->prepare(qq|SELECT musing_id, ref_id, heading, entry, DATE_FORMAT(entry_date, '%M %e, %Y') FROM musings WHERE musing_id = '?'|); $sth->execute($musing_id); } my $entries = $dbh->selectall_arrayref($sql_stmnt); $sth->finish(); return $entries; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://822006]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2024-04-26 07:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found