I'm making my first steps on programming.
I decided to begin with PHP... so be nice if my question is too simple.

I'm doing a SQL query on a shop database where I get something like this:

```
-- Reference -- Buying Cost -- Selling Cost ---- QUANTITY--Product Name--

-----GGHH-----------5---------------10--------------1------qwqwqwqwqwqw--

-----WEFJ-----------1----------------3--------------2------asasasasasas--

-----ERWW-----------20--------------25--------------1------zxzxzxzxzxzx--

-----GGHH-----------5---------------10--------------1------rtrtrtrtrtrt--

-----GGHH-----------10--------------20--------------2------fgfgfgfgfgfg--

-----GGHH-----------33--------------55--------------1------jkjkjkjkjkjk--

```

1 order has 1 reference and 1 order might have 1 products or more.

Read the above table as each line = a certain product of X quantity that belongs to order Z.

What I want to do is a HTML table with each order Reference and the following profit based on selling cost - buying cost = profit.

I'm not figuring out how I can do it.

If each order only had 1 product it would be easy... but since this structure I'm not figuring it out.

Note: I can't change anything in terms of MySQL database. I only can read from it.

Thank you!!