Totaling all values for same ID across multiple columns in PHP

I am trying to add together several different vales for a row that are spread across multiple columns.

The columns of my table are;
product_id, product_name, product_stock_lab, product_stock_storeroom, product_stock_garage.

The ID is unique, the name is the product name, product_stock_XXX contains a numerical value of current stock.

Each product could be stored in multiple locations so I would like to add these together to output a total in PHP for a simple stock management solution.

So far, I’ve not been able to find a way to do it other than in SQL which is not useful for me to display inside a PHP page.

Any help would be greatly appreciated.


Could a for-loop be what you’re looking for? You can collect the values of whatever column you want and store them in an associative array.

What is confusing is the phrase Each product could be stored in multiple locations. Do you mean different databases, different servers, or something else.