I think there's several ways of doing this - its a matter of finding the way you're comfy with and matches with your design.
My one thought would be to try to pull out all your date data in the database with one query and organize the data in a way that makes it somewhat easy to dump from your calendar displaying loop.
If somewhere in your calendar displaying loop you know what day it is, you might do something like:
echo $aDatelist[$day];
Where $aDatelist is an array where each element in the array represents 1 day out of the month. I think the easiest way to do this is to make day 1 array element 1 (or 0 if you're into the zero based arrays). Increment the day counter to the next day and you have the data for that day. Make sense?
What makes this work is when you query the database for your data, you need to pull out the day (not difficult) and use the day value as the array index value.
Just an idea...