I’m building a calendar and I’m really dumb when it comes to arrays.
First of all, I need to query my database, so:
$events = mysql_query ("SELECT id,title,date WHERE date BETWEEN 2009-01-01 AND 2009-01-31")
or die(mysql_error());
So, now I need to order those events so, when I’m echoing my calendar table, I can check this array for events.
In this great Calendar written by David Walsh, he does a query for every day, but I suppose it would be a performance nightmare.
So…any ideas how can I do this?
Ok regarding your comments you can do something like this: Get the events like Davek proposed (note the
ORDER BY!)Then you got the events ordered by the date. To output it you can do this:
Note: This is just a rough sketch, you have to adjust the output of course, but it should give you the right idea.
Output would look like this (in my example):
Edit after comment:
You can write your own function:
But this way you search the the complete array over and over again for each day. You can improve it, if you remove the events you already searched for from the
$eventsarray. So every time you search in a smaller array. But I would only do this if there is a performance issue.