Since it's a lot easier if you want successive results from the query to run horizontally (basically, just keep counting 1,2,3,1,2,3,1,2,3 and every time you hit a 3 end the row and start a new one), I guess you want the results to read downwards.
This is harder; HTML doesn't really know what a table column is.
First off, Set up three arrays for holding results (perhaps strings formatted in preparation for their display).
Next, find out how many results you'll be needing to show.
Divide that by 3 and call the result "cutpoint" or something.
Start reading rows out from the database, and put them into the first array, until you have read "cutpoint" such rows. Then continue reading rows, only this time put them in the second array. When you've read another "cutpoint" rows, switch to filling the third array.
Now you'll be able to go "read from array 1, read from array 2, read from array 3..."
That's only a suggested starting point for a solution. There's plenty of opportunities for fiddling and improving the basic idea; some of them might suggest a method which shortcuts the entire suggestion. But right now I'm not sufficiently conscious to give a bulletproof answer.