将php where子句添加到foreach循环

将php where子句添加到foreach循环,php,foreach,where,Php,Foreach,Where,使用PHP 我正在尝试建立一个事件的时间表(限于接下来的5个),我不想包括任何已经过去的事件。换言之,在事件发生后的第二天,它应该会从计划中消失 这是我的疑问: SELECT * FROM `lfc_events` WHERE event_year >= $year AND event_month >= $month LIMIT 0, 5 我正在使用foreach循环构建表: foreach ($evts as $evt) { $evtnum = substr(

使用PHP

我正在尝试建立一个事件的时间表(限于接下来的5个),我不想包括任何已经过去的事件。换言之,在事件发生后的第二天,它应该会从计划中消失

这是我的疑问:

SELECT * 
FROM  `lfc_events`
WHERE event_year >= $year
AND event_month >= $month
LIMIT 0, 5
我正在使用foreach循环构建表:

foreach ($evts as $evt) {
        $evtnum = substr($evt->event_name, -2);    // returns the number of the event (ex: LFC 21 -- the 21 is returned)
            if ($evt->event_fightcard == "") {
                $evtlink = 'LFC ' . $evtnum;
            }
            else {
                $evtlink = '<a href="' . $evt->event_fightcard . '">LFC ' . $evtnum . '</a>';
            }

        $res.='
            <tr>
                <td>' . $evt->event_month . '/' . $evt->event_day . '/' . $evt->event_year . '</td>
                <td>' . $evtlink . '</td>
                <td>' . $evt->event_city . ',' . $evt->event_state . '</td>
            </tr>';
}

是否可以将where子句添加到foreach循环中?
n将
where
构建到您的SQL查询中,并选择only records>=today。这不排除在该日之前但在未来几个月内发生的事件吗?例如,如果今天是15号,下一个事件发生在下个月的7号,则该事件将被排除在外。我应该指出,我将事件的日期存储在单独的列中(月、日和年)。
foreach ($evts as $evt where $evt->event_day >= $today) {
     // code...
}