I want to create a calendar section on my website where each URL is in the form of a date, which in turn matches a value in my database table. For example, MySite/Calendar/January_1 would match the first three rows in the DB table below…
N | Date | Year | Content
1 | January_1 | 1830 | Buffalo Bill was born.
2 | January_1 | 1969 | Mt. Vesuvius erupted.
3 | January_1 | 1969 | He was elected President.
4 | January_2 | 1944 | World War II started.
I want to display the following:
1830 - Buffalo Bill was born.
1969 - Mt. Vesuvius erupted.
1969 - He was elected President.
Here’s my query…
$stm = $pdo->prepare("SELECT Cal2.N, Cal2.Date2, Cal2.Year, Cal2.Brief
FROM calendar_px Cal2
WHERE Cal2.Date2 = :MyURL
GROUP BY Cal2.Brief");
$stm->execute(array(
'MyURL'=>$MyURL
));
break;
}
while ($row = $stm->fetch())
{
$Year = $row['Year'];
$Brief[] = ''.$Year.' – '.$row['Brief'].'';
}
And this is what I have on the display page…
echo join( $Brief, '<br>' );
It works fine, except that it displays the data twice. It displays all three rows, then it starts over and displays all three rows again.
I turned on error reporting, and there are no errors on the page. I pasted the query into phpMyAdmin > SQL, and it displays fine.
I thought this was what the GROUP BY function is supposed to be used for, which is why I added the GROUP BY clause. But it doesn’t work, no matter what field name I GROUP BY.
I must be making some really simple mistake, but I can’t figure it out. Any tips?