Reputation: 79
I'm building a site (my first!) which lists events, nested when necessary inside year and month headers. I know it's a bit of a mess, but hey!
I've made an error somewhere, and the date field from the MySQL DB isn't being passed correctly. So it just defaults to 01-01-1970
<?php
$query = 'SELECT * FROM events';
$result = mysql_query( $query );
$current_month = 'no_month_given';
$current_year = 'no_year_given';
$year_count = 0;
$month_count = 0;
$year = date("Y", strtotime($row['event_startdate']));
$month = date("M", strtotime($row['event_startdate']));
$startday = date("d", strtotime($row['event_startdate']));
$endday = date("d", strtotime($row['event_enddate']));
while($row = mysql_fetch_array($result))
{
/* YEAR */
if($current_year != $year)
{
$current_year = $year;
echo " <div id=\"year\">
<p class=\"vert\">" .$current_year. "</p>";
$year_count++;
}
/* MONTH */
if($current_month != $month)
{
$current_month = $month;
echo '<div id="month"><h1>' . $current_month . '</h1>';
$month_count++;
}
/* EVENT DETAILS */
}
Upvotes: 1
Views: 226
Reputation: 15616
put these lines inside the while loop:
$year = date("Y", strtotime($row['event_startdate']));
$month = date("M", strtotime($row['event_startdate']));
$startday = date("d", strtotime($row['event_startdate']));
$endday = date("d", strtotime($row['event_enddate']));
because $row isn't defined before and you can't use the $row variable outside the loop because of it.
Upvotes: 2