mricketts Posted January 13, 2011 Share Posted January 13, 2011 I have a mysql database set up with 4 fields - id, month, day, event. The database will be filled with something like: month=Jan, day=4 and event=Meeting. All are text fields. The display will be Jan. 4: Meeting I can set up the PHP to display the database in a unordered list. The code for this is: <?php $result = @mysql_query("SELECT id, month, day, event FROM homecalendar"); if (!$result) { exit('<p>Error performing query: ' . mysql_error() . '</p>'); } while ($row = mysql_fetch_array($result)) { echo '<li>' . $row['month'] . $row['day'] .': ' . $row['event'] . '</li>' ; } ?> How can I limit the code to display items for only the current month and the next month? Quote Link to comment https://forums.phpfreaks.com/topic/224277-help-with-event-listing/ Share on other sites More sharing options...
.josh Posted January 13, 2011 Share Posted January 13, 2011 basically your query would be something like : SELECT id, month, day, event FROM homecalendar WHERE month IN ('january','febuary') ORDER BY month, day As far as how to use dynamic values into that IN (...) it depends on what format your month is. Quote Link to comment https://forums.phpfreaks.com/topic/224277-help-with-event-listing/#findComment-1158756 Share on other sites More sharing options...
Garethp Posted January 13, 2011 Share Posted January 13, 2011 <?php $result = @mysql_query("SELECT id, month, day, event FROM homecalendar WHERE `month`='" . date('M', time()) . "' OR `month`='" . date('M', strtotime("+1 month")) . "'"); if (!$result) { exit('<p>Error performing query: ' . mysql_error() . '</p>'); } while ($row = mysql_fetch_array($result)) { echo '<li>' . $row['month'] . $row['day'] .': ' . $row['event'] . '</li>' ; } ?> That might work. The second part of the where script might not, I'm not sure if Strtotime supports +1 month Quote Link to comment https://forums.phpfreaks.com/topic/224277-help-with-event-listing/#findComment-1158757 Share on other sites More sharing options...
inversesoft123 Posted January 13, 2011 Share Posted January 13, 2011 orrr $result = @mysql_query("SELECT id, month, day, event FROM homecalendar WHERE DATE_SUB(CURDATE(),INTERVAL 30 DAY) <= day"); Quote Link to comment https://forums.phpfreaks.com/topic/224277-help-with-event-listing/#findComment-1158759 Share on other sites More sharing options...
Pikachu2000 Posted January 13, 2011 Share Posted January 13, 2011 You really, really, really should store the date in a DATETIME or DATE type field instead of breaking it into pieces like that. Quote Link to comment https://forums.phpfreaks.com/topic/224277-help-with-event-listing/#findComment-1158762 Share on other sites More sharing options...
mricketts Posted January 14, 2011 Author Share Posted January 14, 2011 Thanks everyone. I got it working. I ended up creating a new table with a DATE filed and using the following code: $result = @mysql_query("SELECT id, date, event FROM eventscalendar WHERE MONTH(date) BETWEEN MONTH(CURDATE()) AND MONTH(CURDATE())+1"); Quote Link to comment https://forums.phpfreaks.com/topic/224277-help-with-event-listing/#findComment-1159189 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.