The way phpAdmin does it, if I remember right, is to use a SHOW TABLE STATUS [database name] query. This will bring back a row for each table in the database. From there, you loop through each table and the (Data Length + Index Length) = table size in bytes. Loop through each table adding those to the mix to get the total for the database. Then divide by 1024 to get kilobytes, divide again for megs, so on and so forth.