View Single Post
Old 07-13-2013, 09:51 PM   #5
tux
tux's Avatar
 
Join Date: Feb 2007
Location: Isle of Wight, that little island right at the bottom of the UK
Posts: 657
Default

Okay I have managed to come up with a solution for this. It gives me the result I need, whether or not it is the best solution I don't know. If anyone has an improved way do please let me know.

PHP Code:
<?php

require('connections/connection.php');//your own database connection script here///////////////////////////////////

/////Select statement to get the months and years for the events///////////////////////////////////////////////////
$m_query             =    "SELECT DATE_FORMAT(from_unixtime(eventTimestamp),'%M %Y') AS eventMY FROM events WHERE eventTimestamp >= UNIX_TIMESTAMP() ORDER BY eventTimestamp ASC ";
$m_result            =    mysql_query($m_query) or die('cannot get results!');//Month and Year from timestamp in DB//
while($monthyear    =    mysql_fetch_assoc($m_result)){
$rows[]                =    $monthyear['eventMY'];//Declare Array//////////////////////////////////////////////////////
}
$MY                    =    array_values(array_unique($rows));//Duplicate Months removed and array keys reset//////////

/////Select statement to get events////////////////////////////////////////////////////////////////////////////////
$e_query             =    "SELECT eventTitle, eventLink, DATE_FORMAT(from_unixtime(eventTimestamp),'%D') AS eventDay, DATE_FORMAT(from_unixtime(eventTimestamp),'%M %Y') AS eventMY FROM events WHERE eventTimestamp >= UNIX_TIMESTAMP() ORDER BY eventTimestamp ASC ";
$e_result            =    mysql_query($e_query) or die('cannot get results!');
while(
$events        =    mysql_fetch_assoc($e_result)){
$event[]                =    $events;
}

/////Display Month and Year with events for each Month below///////////////////////////////////////////////////////
foreach($MY as $my){
echo 
"<strong>".$my."</strong><br>";
foreach(
$event as $e){
if(
$e['eventMY'] === $my){
echo 
$e['eventDay'].", ".$e['eventTitle'].".<br>";
}
}
}
?>
And an example of the output.....

Quote:
October 2013
1st, Lecture: Nepal with Stuart Bennet.
8th, Titlesizer Training and Competition Clarification.
15th, 1st League Print Competition, Judge, Martin Wedge.
22nd, Screen Calibration and Printer Profiles / Practical 1 Print Mounting.
29th, 1st League DIGI Competition incorp. Gordon Richards with Judge, Brian Cope.
November 2013
5th, Lecture: Update on the White Lions of Timbuvarti with Karen Dudley.
12th, 2nd League Print Competition, Judge, Gary Early.
19th, Practical 2, TBC / DVD Presentation.
26th, 2nd League DIGI Competition incorp. Peter Peel (mono).
I hope this is useful to others.
tux is offline   Reply With Quote