Getting a table from the server and putting it into a javascript array

I need to know the best way of fetching an entire table from the server and then inserting each row into a multi-dimensional javascript array. Retrieving the data is no problem (SELECT * FROM table) but how do I then break it down and insert it into the array?

Thanks in advance.

So after much trawling it seems that all of the data from the table needs to be put into a (big) string that can be returned via an echo statement. Is this really the best way to do it? It seems that this string is going to reach ridiculous proportions.