koneill 0 Newbie Poster

I current have this .cgi which is used to display to a user the products they've selected for purchase.
 
I am wondering what is the best and most efficient way to obtain this scenerio:
 
Right now if someone purchases the first motor it is $18 and that displays in the table below but any additional motor is $12 which is where I'm looking for some guidance.
 
I know the item is a motor based on it's description obtained from fields[2]
 
Also - individuals have the ability to enter in a quantity obtained from fields[3] so if an item is a motor and an individual
enters in a value of 2 or greater - the price would be $30 ($18 + $12).
 
 

$table      .= "<TABLE BORDER=1>\n";
$table      .= "<TR><TD>item</TD><TD>design</TD><TD>description</TD><TD>quantity</TD><TD>price each</TD><TD>item total</TD></TR>\n";
 
# Make the individual rows and cells
$r           = 1; #row
$subtotal    = 0; #subtotal
foreach $product (@products) {
  $table    .= "<TR ALIGN=center>\n";
  @fields    = split /\!/, $product;
 
  $itemtotal = (@fields[3] * @fields[4]);
 
  $table    .= "  <TD>@fields[0]</TD>\n";   #item
  $table    .= "  <TD><IMG SRC=\"/Images/smallProductImages/@fields[1].gif\"><BR><FONT SIZE=-1>@fields[1]</FONT></TD>\n";   #design
  $table    .= "  <TD>@fields[2]</TD>\n";   #description
  $table    .= "  <TD>@fields[3]</TD>\n";   #quantity
  $table    .= "  <TD>\$@fields[4]</TD>\n"; #price
  $table    .= "  <TD>\$$itemtotal</TD>\n";
 
  $table    .= "</TR>\n";
 
  # tally each item
  $dvds = 0; $books = 0; $watch = 0; $motor = 0; 

  if (@fields[0] eq "dvd") { $dvds = ($dvds + @fields[3]); }
  if (@fields[0] eq "book") { $books = ($books + @fields[3]); }
  if (@fields[0] eq "watch") { $watch = ($watch + @fields[3]); }
  if (@fields[0] eq "motor") { $motor = ($motor + @fields[3]); }

  # Bump up the subtotal and row number
  $subtotal = $subtotal + $itemtotal;
  $r++;
}

 

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.