Gossamer Forum
Home : Products : DBMan SQL : Discussion :

Adding fields

Quote Reply
Adding fields

I want to know how many products I have left in my inventory, and I would like to add up a specific field, called quantity.

So when I enter a new amount in the "Add to inventory", I select the catalog number, blah blah blah and whichever amount I put on "quantity" in the inventory table, gets added in a global quantity for each product.

For example, I just made 3 new shirts, I go into "Add to inventory", I select product=shirt, the catalog number, etc. AND I enter 3 in the "quantity" field. When I click "Add", the 3 gets added to shirt_inventory, where I already had another 5. So then, I can go to the "main page", where I get the different products I have "8 Shirts" Displayed under the "Shirt" square.

How can I do this? I want to be able to do the same with about 15 different products.

Thanks, Eugenio.

P.S. I would much rather have the program calculate the amount of inventory i have left each time the page is loaded than having it set, but i could live with it.

Last edited by:

ecamty: Jul 3, 2003, 2:37 PM
Quote Reply
Re: [ecamty] Adding fields In reply to
Ok, I want to avoid someone who has this problem to spend 14 hours searching to find the simplest solution possible.

Heres what to do... In the template globals, create a new one (say you call it inventory_total)

Then add the following code:


sub {
my ($total) = $DB->table('table_name')->select(['SUM(field_to_add)'])->fetchrow_array;
if ($total < 1){
$total = '0';

return $total;
Replace table_name and field_to_add with your table and field.