I am trying to print the results the same query in two places on my page,
SELECT beginning_slot, ending_slot, device, orientation FROM devices WHERE rack_id = 2 AND enabled = 1
the result is
This would be the way to do it. You don’t want to bang the DB more than necessary. Granted, in a small, low traffic site it isn’t going to matter, but still…
* I assume “buckets” means arrays as you have shown.
The process of stuffing similar things together is called bucketing (as I think you already know). Hence you put stuff in buckets. That those are implemented by arrays is a detail.
Wouldn’t it be as easy to ORDER BY the row orientation, and notice when the orientation value changes and handle any display things such as changing to a new display table?