The biggest problem you are going to run into is properly supporting things without the boards being easy to shift/tilt due to sitting on top of the mattress. Depending on what space you might have available, building a frame of sawhorse style supports that are large enough to slot over the bed is probably your best bet.
I did something similar a few years back, but I was using a twin bed with parallel headboard & footboard that was the bottom half of a bunk bed, which made it a lot easier for me. I was able to just add two 2x4's between the head & foot, a pair of 4' x 4' particle boards over those, with some pins that sank down through the boards, 2x4's and into the old bunk bed slots.
Later on, we needed the bed to go back to back to bunk bed form, but still wanted to use the table stuff, so we bought sawhorse brackets that allow you to build a collapsable sawhorse out of properly cut 2x4's. Then it was a simple matter of putting holes in the right places on the sawhorses' top beams and assembling the table as we did before, with the sawhorses taking the place of the headboard & footboard.