开发者

Using PHP to select table entries using two date fields and current month

Please help a newbee. I have a table named event_calendar with fields named ec_start_开发者_如何转开发date, ec_end_date and ec_event_name. The first two fields are date fields. It is a small table, with less than 100 entries. I want to list events with a start or end date in the current month, then I want to follow with a list of events with a start or end date in the next month. The two list will be headed by the month name. I would like the dates displayed in the list to be in the format dd/mm.

This is the code I've found to identify the months for the list headers.

$thismonth = mktime(0,0,0,date("n"));
$nextmonth = mktime(0,0,0,date("n")+1);

echo "<h2 class='caps'>";
echo date("n", $thismonth);
echo "</h2>";

echo "<h2 class='caps'>";
echo date("m", $nextmonth);
echo "</h2>";

This is the code I use to pull the entries for this month's (August) activities

$query = "SELECT ec_display,ec_event_name,ec_start_date,ec_end_date FROM event_calendar WHERE month(ec_start_date) = 8 OR month(ec_end_date) = 8 ORDER BY ec_start_date";

The problem is, if I replace the number 8 with the variable $thismonth, it fails.

Finally, how can I display only the dd/mm from ec_start_date and ec_end_date?

I greatly appreciate any guidance, but please be specific as I am very new to this! Thank you!


$thismonth contains a UNIX timestamp returned by mktime. The timestamp for hour 0, minute 0, second 0 of month 8 of this year is 1312862400. That's not 8.

Don't put that in your query, put date('n') (8) in it... or just let MySQL do it

$query = "SELECT ec_display,ec_event_name,ec_start_date,ec_end_date FROM event_calendar WHERE month(ec_start_date) = MONTH(CURRENT_DATE) OR month(ec_end_date) = MONTH(CURRENT_DATE) ORDER BY ec_start_date";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜