I am trying to display retrived DB records in a template (using <TMPL_LOOP>). I have run the query returned by my script in MS Access and it returns a record. However, as part of the script, both from the command line and browser, the retrieved record is not displayed in the template. Other stuff in the template is displayed but not the retrived record. Here's the code with explanations in parenthesis:
Script
#! C:/perl/bin -w use diagnostics; use CGI; use HTML::Template; use DBI; #Creating Object $query=new CGI; $template= HTML::Template->new(filename => 'TechSupportResults.tmpl'); #Setting content type print $query->header('text/html'); #Retrieving values for query (A user can search on CustomerName, Date of Submission, Priority or Ti +cket No. If any value is not selected, the default value is "*" ) $customer = $query->param('CustomerList'); $createMonth = $query->param('ProblemMonth'); $createDay = $query->param('ProblemDay'); $createYear = $query->param('ProblemYear'); $date = $createMonth."/".$createDay."/".$createYear; $priority = $query->param('Priority'); $ticket = $query->param('TicketNo'); retrieveFormData(); fetchData(); displayResults(); (You can ignore this function. This populates the CUStomer drop down i +n the search form. Has no bearing on my problem but I still left it h +ere just in case..) sub retrieveFormData { my $data_string = "dbi:ODBC:TSCenter"; my $username = ""; my $password = ""; connectDB( $data_string , $username , $password ); my $arrayRef = $dbh->selectcol_arrayref('SELECT Customer FROM Cust +omerListTable ORDER BY Customer'); my @loop_data = (); foreach $eachCustomer (@{$arrayRef}) { my %customers = ( CUSTOMER => $eachCustomer, ); push (@loop_data, \%customers); } $template -> param(CUSTOMERLIST => \@loop_data); } # of retrieveFormData (This is where the problem is....specific comments included.) sub fetchData { my $SQL; my $quotedString1 = $dbh->quote("$customer"); my $quotedString2 = $dbh->quote("$priority"); my $quotedString3 = $dbh->quote("$ticket"); my $quotedString4 = $dbh->quote("$date"); my $temp1 = "SELECT TicketNo, Customer, UserName, DateSubmission, +Via, Issues, SupportType, Description, Detail, AssignTo, Status, Rema +rks, Priority, ETD "; my $temp2 = "FROM TSIssuesTable "; my $temp3 = "WHERE "; my $temp4 = "Customer LIKE $quotedString1 AND Priority LIKE $quote +dString2 AND TicketNo LIKE $quotedString3 AND DateSubmission LIKE $qu +otedString4"; $SQL = $temp1.$temp2.$temp3.$temp4; print $SQL; (Flow is fine till here. This statement prints - SELEC +T TicketNo, Customer, UserName, DateSubmission, Via, Issues, SupportT +ype, Description, Detail, AssignTo, Status, Remarks, Priority, ETD FR +OM TSIssuesTable WHERE Customer LIKE 'Support Concepts' AND Priority +LIKE '*' AND TicketNo LIKE '*' AND DateSubmission LIKE '*/*/*'-When I + copy and run this query in MS Access a record is returned.) my $rows = $dbh->selectall_arrayref($SQL,{Columns =>{}}) ; print $rows; <font color="red">(FLow is fine here too-this stateme +nt prints ARRAY(0x1ed0bb0) )</font> foreach (@$rows) { print "I say $_\n"; (Problem here-no output on screen.) } $template->param(ROWS => $rows || []); disconnectDB(); } # of fetchData sub displayResults { #Printing information print $template->output; } # of displayResultScreen sub connectDB { my $data_string = $_[0]; my $username = $_[1]; my $password = $_[2]; $dbh = DBI->connect( $data_string , $username , $password ) or die + "Could not connect to database"; }# of connectDB sub disconnectDB { $dbh->disconnect(); }# of disconnectDB
The template:
<html> <head> <meta http-equiv="Content-Language" content="en-us"> <meta http-equiv="Content-Type" content="text/html; charset=windows-12 +52"> <title>Search</title> <link rel="stylesheet" type="text/css" href="./ss.css"> <script language="JavaScript" type="text/javascript" src="../TechSuppo +rtScripts.js"></script> </head> <body> (Including the search bar. This is succesfully displayed in the output + after the script is run) <!-- TMPL_INCLUDE NAME = "SearchTechSupport.tmpl" --> <p><b>Results</b></p> <table border="1" > (The header row for results-also displayed in the output-You can skip +thru this) <tr> <td> <b><font>Ticket #</font></b></td> <td> <font><b>Reseller</b></font></td> <td> <b><font>End User Name</font></b></td> <td> <font><b>Reported On</b></font></td> <td> <font><b>Reported By</b></font></td> <td> <font><b>Product</b></font></td> <td> <font><b>Support Type</b></font></td> <td> <font><b>Brief Description</b></font></td> <td> <font><b>Details</b></font></td> <td> <font><b>Assigned To</b></font></td> <td> <font><b>Issue Status</b></font></td> <td> <font><b>Remarks</b></font></td> <td> <font><b>Priority</b></font></td> <td> <font><b>Closure Date</b></font></td> </tr> (Problem here-this row -for displaying DB-retrieved data is not displa +yed) <!-- TMPL_LOOP NAME=ROWS --> <tr> <td> <!-- TMPL_VAR NAME=TicketNo --></td> <td> <!-- TMPL_VAR NAME=Customer --></td> <td> <!-- TMPL_VAR NAME=UserName --></td> <td> <!-- TMPL_VAR NAME=DateSubmission --></td> <td> <!-- TMPL_VAR NAME=Via --></td> <td> <!-- TMPL_VAR NAME=Issues --></td> <td> <!-- TMPL_VAR NAME=SupportType --></td> <td> <!-- TMPL_VAR NAME=Description --></td> <td> <!-- TMPL_VAR NAME=Detail --></td> <td> <!-- TMPL_VAR NAME=AssignTo --></td> <td> <!-- TMPL_VAR NAME=Status --></td> <td> <!-- TMPL_VAR NAME=Remarks --></td> <td> <!-- TMPL_VAR NAME=Priority --></td> <td> <!-- TMPL_VAR NAME=ETD --></td> </tr> <!-- /TMPL_LOOP --> </table> </body> </html>
I am posting all of my code bcoz I have been on this problem for sometime-tried another forum but have not got a response-so I thought I might as well provide all details.

In reply to HTML::Template-Displaying DB Records by thisisperl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.