Dreamweaver CS4 - Table prices

Hi all,

Im wondering if some people are willing to help me out please.

Im currently building a website and i have a table with a number of options including prices.

Column A has the price
Column B has the fare type
Column C has how many tickets people want
Column D will have the total price

I want to know how on earth do you get via HTML Column C multiplied by Column A and the total price in Column D. Excel its easy but im pulling my hair out with tables on Dreamweaver CS4.

Can someone point me in the right direction please.

Cheers

HTML is a markup language, and can’t do any calculations for you. You have to manually enter the product of A and C into D.

You could technically do it with Javascript, but this would both require extra markup and would mean that people with Javascript disabled can’t see the numbers in the last column. If you want automation, you’d be best off with a server-side scripting language, such as PHP, but unless it’s a fairly big table, it’s probably faster to type it manually.

Cheers for that information.

Can anyone point me in the right direction or to a website with a PHP code for me to be able to do this? Ive seen it done on other websites, so i know it can be done, just sounds like a pain in the behind to set it up.

Cheers

If your information is hardcoded in the table, then you can’t do it with PHP (technically, you could set up a combination of an .htaccess file that re-directs to a PHP script which parses the HTML file and fills out the information, but this will take much longer than filling it out by hand.

If you have the information stored in arrays (or preferably a database), it’s fairly straight-forward:

$column_a = array(
 10,
 20,
 30,
 40,
 50
);
$column_b = array(
 "Fare type",
 "Fare type",
 "Fare type",
 "Fare type",
 "Fare type"
);
$column_c = array(
 1,
 2,
 3,
 4,
 5
);

printf("<table>\
 <thead>\
  <tr>\
   <th scope=\\"col\\">Price</th>\
   <th scope=\\"col\\">Fare type</th>\
   <th scope="\\col\\">Quantity</th>\
   <th scope=\\"col\\">Total</th>\
  </tr>\
 </thead>\
 <tbody>\
");

foreach($column_a as $key=>$value) {
 printf("  <tr>\
");
 printf("   <td>&#37;s</td>\
", $value);
 printf("   <td>%s</td>\
", $column_b[$key]);
 printf("   <td>%s</td>\
", $column_c[$key]);
 printf("   <td>%s</td>\
", $value * $column_c[$key]);
 printf("  </tr>\
");
}
printf(" </thead>\
</table>");