MiniVend Akopia Services

[Date Prev][Date Next][Thread Prev][Thread Next][Minivend by date ][Minivend by thread ]

Re: loop through Products




Dmitriy:

We had a client insist that we had to use their three databases "As-Is." 
Meant with 10-30 fields in each, 8 of which would be used for any 
particular item. 8 DIFFERENT fields for any particular item. 

This is the monstrosity we came up with. Deformed child, but it works :-)

The Usertag section returns proper fieldnames for which of the three
files we were looking at.

 -- catalog.cfg --

UserTag fieldnames Order file                                                   
UserTag fieldnames Routine <<EOF                                                
sub {                                                                           
  my ($dbfile) = @_;                                                            
  if($dbfile eq 'tools') {                                                      
    return "catalog_no description qty material height width length depth head_length head_diameter head_weight head_number handle_length handle_number voltage standard_cross_bars optional_cross_bars input_capacity output_capacity input_drive output_drive

 ratio weight price";                                            
  } elsif($dbfile eq 'clamps') {                                                
    return "description opening throat_depth clamping_pressure pressure_w_lever pressure_w_handle clamping_range load_limit avg_pull rail_size height width length diameter thickness jaw_height min max thread_size stud_size diff_matl_range uniform_matl_ran

ge t_clearance capacity_for_sides miter_each_side clamping_blocks tgk_adapters tgk_opening tgk_opening_qty tgj_opening tgj_opening_qty dim_b dim_c dim_d dim_e dim_f weight price";
  } elsif($dbfile eq 'fluids') {                                               
    return "catalog_no description size case_qty type color weight price";      
  } else {                                                                      
    return "unknownfile";                                                       
  }                                                                             
}                                                                               

 -- flypage.html --

[item-field details] is the name of the particular database (of three)
that contains the details about the item.

  <!-- get valid list of populated fields for this table/key combo -->
  <!-- search returns first match. assume all fields are same -->
  <!-- won't we have fun if that's not true -->
  [set show_fields] [/set]
  [loop search="se=[item-code]/ml=1/fi=[item-field details].asc/id=|"]
    [loop with="-a" arg="[fieldnames [item-field details]]"]
      [if data [item-field details]::[loop-code-a]::[loop-code]]
        <TD><FONT FACE="Verdana,Arial,Helvetica" SIZE="-1" COLOR="#FFFFFF">
        [perl]
          $title = '[loop-code-a]';
          @words = split(/_/, $title);
          foreach $word (@words) { $word = ucfirst($word); }
          $title = join " ", @words;
          return $title;
        [/perl]
        </FONT></TD>
        [set name="show_fields" interpolate=1][scratch show_fields][loop-code-a] [/set]
      [/if]
    [/loop]
  [/loop]
  </TR>
  <!-- table data rows repeat same search but get all rows now -->
  [set rowcolor]FFFFFF[/set]
  [loop search="se=[item-code]/fi=[item-field details].asc/id=|"]
    <TR ALIGN="center" VALIGN="TOP" BGCOLOR="#[scratch rowcolor]">
    <TD ALIGN="left"><FONT FACE="Verdana,Arial,Helvetica" SIZE="-1">[loop-code]</FONT></TD>
    [loop with="-a" arg="[scratch show_fields]"]
      <TD><FONT FACE="Verdana,Arial,Helvetica" SIZE="-1">
      [data base="[item-field details]" field="[loop-code-a]" key="[loop-code]"]
      &nbsp;</FONT></TD>
    [/loop]
    </TR>
    <!-- this dumb construct sets every other row to grey -->
    [if scratch rowcolor eq "FFFFFF"]
    [then]
      [set rowcolor]CCCCCC[/set]
    [/then]
    [else]
      [set rowcolor]FFFFFF[/set]
    [/else]
    [/if]
  [/loop]
  </TABLE>

Without having to deal with three files, your problem is somewhat
simpler. Thought I'd post the whole thing in case somebody needed it.
Or wants to help improve it :-)

This, btw, produces marginally acceptable output in terms of speed. 
If we ever load our server any higher, we'll probably have to spin 
static pages.

  -- Loy

--
Loy Ellen Gross * Web Designer & Programmer * Xcalibur Internet
  Voice: 716-344-1114 * design@iinc.com * http://www.iinc.com







Search for: Match: Format: Sort by: