thisisperl has asked for the wisdom of the Perl Monks concerning the following question:
#! 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
<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>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: HTML::Template-Displaying DB Records
by perrin (Chancellor) on May 25, 2004 at 04:13 UTC | |
by thisisperl (Novice) on May 25, 2004 at 18:49 UTC | |
by perrin (Chancellor) on May 25, 2004 at 20:27 UTC | |
by thisisperl (Novice) on May 25, 2004 at 21:23 UTC | |
by perrin (Chancellor) on May 26, 2004 at 16:51 UTC | |
|
Re: HTML::Template-Displaying DB Records
by Hagbone (Monk) on May 25, 2004 at 01:06 UTC | |
by perrin (Chancellor) on May 25, 2004 at 03:41 UTC |