bristols Posted October 1, 2009 Share Posted October 1, 2009 I have a list of about 60 events. This list is in one HTML file. I want to have a 'Forthcoming Events' list displayed on every page of my website, showing three forthcoming events from my list of 60 at a time. I want the events shown in the Forthcoming list to automatically update itself so that only forthcoming events are ever shown. My full list of 60 is marked up in one HTML file, using a TABLE. In the code, the events start after the TBODY tag. Each event has its own table row (TR). It begins like this: <table class="events"> <thead> <tr> <th id="event-date">Date</th> <th id="event-title">Title</th> </tr> </thead> <tbody> <tr class="vevent event-performance"> <th headers="event-date"><abbr class="dtstart" title="2009-10-01T2000+0100">01 Oct 2009</abbr></th> <td headers="event-title" class="summary"><a href="/events/2009/first-event.html" rel="bookmark">First Event</a></td> </tr> <tr class="vevent event-radio"> <th headers="event-date"><abbr class="dtstart" title="2009-10-02T1000+0100">02 Oct 2009</abbr></th> <td headers="event-title" class="summary"><a href="/events/2009/second-event.html" rel="bookmark">Second Event</a></td> </tr> .... I am a complete PHP novice! Would anyone know how I could grab three forthcoming events at a time from this list, and output those three in EXACTLY the same code as shown above to all the pages of my website? I realise that I would need to produce a 'forthcoming events' template and include that in my web pages. I just don't know how to produce that template! Any help or pointers would be much appreciated! Link to comment https://forums.phpfreaks.com/topic/176191-events-list/ Share on other sites More sharing options...
gr1zzly Posted October 2, 2009 Share Posted October 2, 2009 This would be better and a lot easier if you were using a mysql database instead of the html table, since the php / sql used to interact with the database would be a lot simpler than handling files. Link to comment https://forums.phpfreaks.com/topic/176191-events-list/#findComment-928971 Share on other sites More sharing options...
cags Posted October 2, 2009 Share Posted October 2, 2009 Is the format of the table in your control? Will it always look exactly like that? So long as it will always appear the same, something like this could work... preg_match_all("/<th headers=\"event-date\"><abbr.*?>(.*)?<\/abbr><\/th>/", $src, $output); $dates = $output[1]; preg_match_all("/<td headers=\"event-title\".*?><a href=\".*?>(.*)?<\/td>/", $src, $output); $events = $output[1]; echo '<pre>'; print_r($dates); print_r($events); echo '</pre>'; It's far from perfect with regards to Regex, but hopefully should do the job. Link to comment https://forums.phpfreaks.com/topic/176191-events-list/#findComment-929041 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.