Hi,
Short and to the point.
1. I'm using this script to dump information from a database (and it works, yes :).
dump.pl
-----------------------------------------------------------------
#!/usr/bin/perl
use CGI qw/:standard :html3/;
use CGI::Carp qw(fatalsToBrowser);
use DBI;
use DBD::mysql;
my $DBName = "test";
my $DBHost = "localhost";
my $DBUser = "test";
my $DBPass = "dev";
my $DBType = "mysql";
my $DBPort = "3306";
sub db_connect {
my ($result);
$result = DBI->connect( "DBI:$DBType:database=$DBName;host=$DBHost
+",
"$DBUser", "$DBPass", { 'RaiseError' => 0 } ) || &error("Unable to
+ connect to database");
return $result;
}
sub db_query {
my ($result, $query);
$query = $_[0];
$result = &db_connect->prepare($query) || &error("Unable to query
+the database");
$result->execute();
return $result;
}
# outer loop
my $query1 = &db_query("SELECT id, title FROM sections");
while (my $rows1 = $query1->fetchrow_hashref()) {
print "Section: " . $rows1->{title}."\n";
my $sectionid = $rows1->{id};
# inner loop
my $query2 = &db_query("SELECT title FROM pages WHERE sectioni
+d = $sectionid");
while (my $rows2 = $query2->fetchrow_hashref()) {
print "-> Page: " . $rows2->{title}."\n";
}
}
-----------------------------------------------------------------
2. Since I have started using HTML::Template on my webpage, I have to port this script to get use of a template.
The template looks something like this:
dump.html
-----------------------------------------------------------------
<TMPL_LOOP NAME="SECTIONS">
Section: <TMPL_VAR NAME="TITLE"><br>
<TMPL_LOOP NAME="PAGES">
-> Page: <TMPL_VAR NAME="TITLE"><br>
</TMPL_LOOP>
</TMPL_LOOP>
3. I have tried to make a new script for HTML::Template, but I can't get the script working with the template because of the outer/inner loop.
Somebody out there with a solution? :-)
Regards, Eivind Hestnes
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.