therealwesfoster Posted April 2, 2008 Share Posted April 2, 2008 I'm wanting to get all of the rows from the table events and displayed them chronologically by month. Example: January Ev 1 Ev 2 April Ev 4 Ev 5 etc. I only want the month "category" to show up IF there is an event in it. Here's my problem. The dates of the events are stored as a unix timestamp in the DB. How can I loop through an array of months ($months = array("jan","feb" etc..)) and do an SQL query for each one? Here's what it would look like: <?php $months = array("jan","feb","mar"); foreach ($months as $key) { $sql = mysql_query("SELECT * FROM events WHERE DATE_MONTH_NAME(ev_date)='{$key}'"); while ($row = mysql_fetch_array($sql)) { // do stuff } } ?> Hope im making sense. Thanks Link to comment https://forums.phpfreaks.com/topic/99263-solved-select-from-table-where-date_month-month-question/ Share on other sites More sharing options...
therealwesfoster Posted April 2, 2008 Author Share Posted April 2, 2008 Ok, i solved it. Here's my code for anyone who has this problem. <?php foreach ($months as $key) { $query = mysql_query("SELECT * FROM events WHERE FROM_UNIXTIME(ev_date,'%M')='{$key}' ORDER BY ev_date ASC LIMIT 16",$dbh) or die("ERR: ".mysql_error()); while($arr = mysql_fetch_array($query)) { // do stuff } } ?> Link to comment https://forums.phpfreaks.com/topic/99263-solved-select-from-table-where-date_month-month-question/#findComment-507914 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.