-
Display values in tablefields after assigning to varnames
Hello All,
I want to display field values in a table after assigning them to variable names. How is this possible. I tried fetchrow_arrayref and fetchall_arrayref. All I need is to diplay in a table column in webpage. Help me with a sample code, if possible, asapHelp me
Thanks in advance
Karthikeyan
-
Solution here!!!
After setting the connection up:
-------------------------------
while(my $ref = $sth->fetchrow_arrayref
{
my ($f1,$f2,$f3) = @{$ref};
my $table = $query->startTable(COLS=>[gettext("f1"),
gettext("f2"),
gettext("f3") ] );
$table .= $query->addTableLine(DATA=>[
$f1,
$f2,
$f3 ] );
}
$table .= $query->endTable();
This works fine for me. Any other solution is also welcome.
-
I prefer this skeleton:
Code:
$sql = "SELECT f1,f2,f3 FROM tablename";
$sth = $dbh->prepare( $sql );
$rv = $sth->execute;
if ( $rv =~ /^0E0/ ) {
# error routine here - we did not receive anything from mysql...
} else {
while ( ( $retval1, $retval2, $retval3 ) = $sth->fetchrow_array() ) {
# do whatever with the vars here
}
}
As you can see, it has a built in error checking for cases where we do not receive anything from MySQL ( empty result ).
Cheers
-
Thanks a many
Hi Nico,
Thx fow error checking mechanism. I can now implement in my project at all places.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|