revraz Posted November 15, 2007 Share Posted November 15, 2007 I'm trying to figure out the best way to populate a Calendar page with data from a database. I have the code that will generate the Table with Days of the week, but I'm at a loss on how to populate this with data from a database. Do I build the calendar and then for every day that I generate a cell, query the DB or should I load the DB in an Array and compare that to the date of the cell? Quote Link to comment https://forums.phpfreaks.com/topic/77487-solved-populate-a-calendar-page-with-mysql-data/ Share on other sites More sharing options...
s0c0 Posted November 15, 2007 Share Posted November 15, 2007 When I've had to do this I used an array. In fact I'll have two arrays. One contains the days of the month (ie. cellArr[1]) for displaying the actual days on the calendar. As it loops through, my second array's key is the day of the month as a number, and its element is the data I want displayed. So when I'm looping through the cell array to show the actual cells I just do something like $dataArr[cellArr[$i]] to display the data I want. Does that make sense? Quote Link to comment https://forums.phpfreaks.com/topic/77487-solved-populate-a-calendar-page-with-mysql-data/#findComment-392348 Share on other sites More sharing options...
revraz Posted November 15, 2007 Author Share Posted November 15, 2007 Thats almost exactly how I was thinking I should do it, but the only problem I can forsee is I will have multiple entries per day for different times. I really tried to think of a way to make the array key the same as the day, but I dont see how with multiple entries like that. I will probably only have 2 entries per day, but my project may require me to have more. So maybe I should do my query based on per date and create an array for each date? I am not sure if that is efficient or not, what do you think? Quote Link to comment https://forums.phpfreaks.com/topic/77487-solved-populate-a-calendar-page-with-mysql-data/#findComment-392392 Share on other sites More sharing options...
s0c0 Posted November 15, 2007 Share Posted November 15, 2007 No stick with that line of thought. Where in the example I gave for the $dataArr array, just make it multi-dimensional. That way you can foreach through that array and display multiple pieces of data for that day. For instance: foreach($dataArr[cellArr[$i]] as $data) { echo $data.'<br/>'; } Something like that, do you follow? Multidimensional array is essentially an array of arrays, but you do not want to have to manage multiple separate arrays. Quote Link to comment https://forums.phpfreaks.com/topic/77487-solved-populate-a-calendar-page-with-mysql-data/#findComment-392433 Share on other sites More sharing options...
revraz Posted November 16, 2007 Author Share Posted November 16, 2007 I really didn't want to use a 3d Array, maybe I'll use a UL display instead of a Table and use CSS to display it instead. Thanks for the tips though. Quote Link to comment https://forums.phpfreaks.com/topic/77487-solved-populate-a-calendar-page-with-mysql-data/#findComment-392888 Share on other sites More sharing options...
revraz Posted January 5, 2008 Author Share Posted January 5, 2008 Just wanted to say thanks, I did end up using a Multi-Dimensional array and it worked great. Quote Link to comment https://forums.phpfreaks.com/topic/77487-solved-populate-a-calendar-page-with-mysql-data/#findComment-431035 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.