when you click on July for example I want to have all the events that fall within July appear. In my database I have a start date and an end date field.
The problem I'm having is if something falls in the middle of the month such as an event that goes July 15th - July 19th.
Whats the best way to pull these records out of the database?
The code I have right now only pulls out the record if its between July 1st and July 31st. I'm having a brain fart and can't think of the solution.
Here is the mysql code I'm using
Code: Select all
<?php
SELECT * FROM board_events as be, board_member as bm WHERE be.member_id = bm.member_id AND '$key' BETWEEN start_date AND end_date
?>Here is some ugly code I can use that selects EVERYTHING in the events table then loops through for what matches the current month. It works but I think its rather inefficient.
Code: Select all
<?php
$result = query_db("SELECT first_name, last_name, page, picture, location,event_desc, DATE_FORMAT(start_date,'%m') as start, "
."DATE_FORMAT(end_date,'%m') as end, DATE_FORMAT(start_date,"%M %e, %Y") as sdate, "
."DATE_FORMAT(end_date,"%M %e, %Y") as edate FROM board_events as be, board_member as bm WHERE be.member_id = bm.member_id");
while($row = mysql_fetch_array($result))
{
if($key >= ($row['start']) AND $key <= ($row['end']))
{
echo '<TR>';
echo '<TD valign="top">';
echo ($row['sdate']).' - <BR>'.($row['edate']);
echo '</TD>';
echo '<TD valign="top">';
echo '<a href="'.($row['page']).'">'.($row['first_name']).' '. ($row['last_name']).'</a><BR>';
echo ($row['event_desc']);
echo '</TD>';
echo '<TD valign="top" align="right">';
echo ($row['location']).'<BR><img src="'.($row['picture']).'" width="65" height="65" border="1">';
echo '</TD>';
echo '</TR>';
} // end if date check
}
?>