I am trying to create a page in which I present an inventory from a MySQL backend. Here is a rough example of the table I have.

```
id,Server_Type,Status
 1,BL460,Available
 2,BL460,Available
 3,BL460,Reserved
 4,BL460,Reserved
 5,BL460,Reserved
 6,DL360,Reserved
 7,DL360,Reserved
 8,DL360,Reserved
 9,DL580,Available
10,BL460,Available`

```

To display these items on the page, I need to group each item by "Server\_Type." However, simply grouping the item by "Server\_Type" in my SQL query is not enough as the unique ID of each item needs to be preserved and represented.

I want to present the choices to the end-user like this on the web page (using above table as our data):

`BL460 - Amount: 3
DL360 - Amount: 0
DL580 - Amount: 1`

NOTE: I need items with a 0 "Available" amount to display on the page as well.

To the end-user, it does not matter what the unique id of the server is - if he/she chooses 2 BL460s, then during checkout any 2 BL460s in an "Available" status need to be switched over to "Reserved" status - does not matter which ones (I was thinking of just having it do by ASC order).

The issue I keep having is how to present the page in PHP format. I need a way to be able to present each value as an option in the page (even the id, though that will remain hidden on the page since it is not important to the end-use). I tried doing this as an array, but I don't know enough about PHP to use array data and properly present it in the page.

Does anyone know how this could be accomplished?

EDIT: So let me add some more info - I've done this query:
`SELECT *, COUNT(CASE WHEN Status = 'Available' THEN 1 ELSE NULL END) AS Amount FROM products GROUP BY id`

Which presents a table like this:

`id,Server_Type,Status,Amount
1,BL460,Available,1
2,BL460,Available,1
3,BL460,Reserved,0
4,BL460,Reserved,0
5,BL460,Reserved,0
6,DL360,Reserved,0
7,DL360,Reserved,0
8,DL360,Reserved,0
9,DL580,Available,1
10,BL460,Available,1`

And can write an array like this: `$amounts = array(); foreach($results as $entry) {if($entry['Amount'] == 1) {if(isset($amounts[$entry['Server_Type']])) {$amounts[$entry['Server_Type']]++;} else {$amounts[$entry['Server_Type']] = 1;}}};`

Which produces a result like this: `array(2) { ["BL460"]=> int(3) ["DL580"]=> int(1) }`

But that still doesn't give me Server\_Types with a 0 amount (though I supposed I could just define another array to give the desired result), nor do I know enough about PHP to present that data in html in the format described above. I suppose my biggest issue is putting an array like that into html format. Does anyone know - or...does anyone know of a better solution?