Database Reference
In-Depth Information
}
else
{
$row_str .= td ( $val [ $i ]);
}
}
push ( @rows , Tr ( $row_str ));
}
return table ({ - border => "1" }, @rows );
}
make_table_from_query() does some extra work to right-justify numeric columns so
that the values line up better. It also enables you to pass values to be bound to placeā€
holders in the statement; specify them after the statement string:
my $tbl_str = make_table_from_query (
$dbh ,
"SELECT
year AS Year, artist AS Artist, title AS Title
FROM cd
WHERE year < ?
ORDER BY artist, year" ,
1995
);
print $tbl_str ;
To display a table in such a way that the user can click any column heading to sort the
table's contents by that column, see Recipe 20.11 .
The &nbsp; Trick for Empty Table Cells
A display problem sometimes occurs for HTML tables that include borders around cells:
when a table cell is empty or contains only whitespace, some browsers show no border
around the cell. This makes the table look irregular. To avoid this problem, the
make_table_from_query() function puts a nonbreaking space ( &nbsp; ) into cells that
would otherwise be empty, so that borders for them display properly.
19.4. Displaying Query Results as Hyperlinks
Problem
You want to create clickable hyperlinks from database content.
Solution
Add the proper tags to the content to generate anchor elements.
 
Search WWH ::




Custom Search