lauralee Posted February 2, 2010 Share Posted February 2, 2010 I have a calendar page in which the events are listed according to Year, Month, Day, and Time. I would like to have all of the events for the current month and future months listed under that month's heading without having to duplicate the month name each time. And, the same for the day, and the time of day, so that it displays in an outline or table form. I assume that I would use a loop and array, but I can't get the effect I want. The code below is what I have used. But I don't want to have to specify the year, month, etc. Can I set the year as a variable, then SELECT the year from the database that matches the variable? Then, set the month as a variable and SELECT all of the data that matches that variable? And, on to the day, and time of day so that I don't have to print each year, month, day, time for every event that is in the database that matches. Can you show me the code that would make that happen?//Request all of the non-recurring events$result = @mysql_query('SELECT event, mo, dt, yr, hr, min, am_pm FROM calendar WHERE yr="2010" AND mo="February" AND recurring="no" ORDER BY dt, am_pm, hr, min'); if (!result) { exit('<p>Error performing query: ' . mysql_error() . '</p>');}while ($row = mysql_fetch_array($result)) { echo '<p><em class="diff">' . $row['hr'] . ':' . $row['min'] . ' ' . $row['am_pm'] . '</em> ' . $row['event'] . '</p>';} Link to comment Share on other sites More sharing options...
jeffman Posted February 3, 2010 Share Posted February 3, 2010 Variables work just fine, and they make more flexible queries most of the time, anyway. Something like this? $yr = $years[$i]; // for example$sql = "SELECT stuff FROM calendar WHERE yr='$yr'";$result = @mysql_query($sql); Enough to get you thinking? Link to comment Share on other sites More sharing options...
lauralee Posted February 4, 2010 Author Share Posted February 4, 2010 Yeah. I thought it might be something simple like a variable, but I wasn't sure how to write it. Thanks. I'll try it with yr first, then if I can figure it out, I'll plug it in for the rest of the variables like month, day, time.One more thing....How can I write it if I don't want the calendar listing to show up if the time, day, month, or year has already past? Right now, I'm having to go in and delete the events if they are old. A code using CURDATE? Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.