What I am faced with is the SELECT constraints need to be dynamic and the list could 
be up to 20 fields. When I output the rows, I need each to split each column into a 
separate cell in a table. Here is what I have done in the past, but I am trying to 
remove the HTML from the code:

 foreach $ar_row (@dbRows)
 {
  foreach $ar_column (@$ar_row)
  {
    # set color to (odd)white || (even)lt grey 
   $color = (&odd_or_even($count) == 0) ? "#DDDDDD" : "#FFFFFF";  
   $nameValue = "";
   $columnHtml = "";
   $columnHtml .= qq[  <TR BGCOLOR="$color">\n]; #apply color to row
   my $adj_count = $count + 1;
    # inset row count as first column
   $columnHtml .= qq[    <TD>$adj_count</TD>\n]; 
   my $col_count = 0;
   
   foreach $column (@$ar_column)
   {
    if ($column eq "") # if cell is empty
    {
     $column = "&nbsp\;";
    }
    if ($col_count == 0) # if first column, add as link to view part
    {
     $columnHtml .= qq[    <TD nowrap>];
     $columnHtml .= qq[<A HREF="javascript:goToViewPart('$column')" TITLE="View Part 
$column" STYLE="color:#ff0000">$column</A>];
     $columnHtml .= qq[    </TD>\n];
    }
    else
    {
     $columnHtml .= qq[    <TD nowrap>$column</TD>\n];
     $nameValue .= qq[$column\|];
    }
    $col_count++;
   }
   $columnHtml .= qq[  </TR>\n];
   $html .= $columnHtml;
   $count++;
  }
 }
 return ($html, $count);

____________________________________________________
  Dale Hanzelka                          480-970-0200 x932
  Senior Application Specialist      480-970-1331 (fax)
  Intercept Technology Inc.(AZ)   www.INTERCEPT.com
  Intercept Design Group             www.InterceptDG.org
  



----- Original Message ----- 
From: "John" <[EMAIL PROTECTED]>
To: "'Dale W. Hanzelka'" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Tuesday, September 28, 2004 3:22 AM
Subject: RE: [htmltmpl] How to Put reference array in to structure fro use in H::T?




>From what you have described, you don't need a nested loop, so something
like this example should do:


Pick up your data, you can use execute and fetchall_arrayref methods if
that suits you better.

my $resultref = $dbh->selectall_arrayref('SELECT name, age, sex FROM
People');
die("Database Error: " . $dbh->errstr) unless defined $resultref;



Then map the results into an array (This is all one line). 


my @loop = map { { name => $_->[0], age => $_->[1], sex => $_->[2] } }
@$resultref;


Then send it to template.

my $template = HTML::Template->new(filename => 'whatever.tmpl');
$template->param(LOOP => [EMAIL PROTECTED]);
print $template->output;


In tmpl:

<TMPL_LOOP NAME="LOOP">
<TMPL_VAR NAME="name"> - <TMPL_VAR NAME="age"> - <TMPL_VAR
NAME="sex"><br>
</TMPL_LOOP>


Resulting HTML:

Pete - 21 - Male<br>
Sally - 26 - Female<br>
Etc...

Hope this helps.

Cheers

John


-----Mensaje original-----
De: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] En nombre de
Dale W. Hanzelka
Enviado el: lunes, 27 de septiembre de 2004 15:22
Para: [EMAIL PROTECTED]
Asunto: [htmltmpl] How to Put reference array in to structure fro use in
H::T?

I am using the Perl DBI to access a database. In particular, I' calling
the fetchall_arrayref.

How do I get the returned information into a usable structure so that I
can loop through each row, then each column in the row?

The returned info is as such:

Reference --> Reference to Row0 --> ( col0, col1, col2, etc...)
                     Reference to Row1 --> ( col0, col1, col2, etc...)
                     etc...

I can acceccs it using the below loop:

 foreach my $array (@array)
 {
  my($i, $j);
  for $i ( 0 .. $#{$array} )
  {
   my $count = ($i + 1);
   print "ROW $count\t";
   for $j ( 0 .. $#{$array->[$i]} )
   {
    $array->[$i][$j] = "NULL" if ($array->[$i][$j] eq "");
    print "$array->[$i][$j]\t";
   }
   print "\n";
  }
 }

How do I get the information into correct structure to use as a nested
loop in my template?

Thanks in Advance!
-Dale


-------------------------------------------------------
This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
Project Admins to receive an Apple iPod Mini FREE for your judgement on
who ports your project to Linux PPC the best. Sponsored by IBM.
Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php
_______________________________________________
Html-template-users mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/html-template-users

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.768 / Virus Database: 515 - Release Date: 22/09/2004
 

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.768 / Virus Database: 515 - Release Date: 22/09/2004
 



-------------------------------------------------------
This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
Project Admins to receive an Apple iPod Mini FREE for your judgement on
who ports your project to Linux PPC the best. Sponsored by IBM.
Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php
_______________________________________________
Html-template-users mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/html-template-users


-------------------------------------------------------
This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
Project Admins to receive an Apple iPod Mini FREE for your judgement on
who ports your project to Linux PPC the best. Sponsored by IBM.
Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php
_______________________________________________
Html-template-users mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/html-template-users

Reply via email to