Main Content

What FGW passengers want to talk about / and PHP programming to find out

Archive - Originally posted on "The Horse's Mouth" - 2015-01-01 13:32:17 - Graham Ellis

Much of my recent talk and examples on this blog recently have stressed robust, tested, re-usable code, and that's vital in the majority of applications. However, there are occasions where a "one-off" is needed such as this morning when I wanted to list the most popular subjects covered on our First Great Western Passenger Forum last year.

Here are the results I wanted (no. of posts, subject number, subject as text):
  899 - 13544 - Weather disruption across the FGW network, February and March 2014
  638 - 4600 - FGW 1st Class - ongoing discussion of the benefits and their apparent reduction
  589 - 14689 - Thames Valley signalling problems causing delays - ongoing, since October 2014
  452 - 6405 - Reading Station improvements
  390 - 5508 - First Great Western on-board catering, HST buffets, Travelling Chefs and Pullmans
  334 - 3098 - Dawlish Avoiding Line - ongoing discussion, merged topic
  270 - 14258 - Thames Valley signalling problems - big delays - July 2014
  175 - 5066 - Great Western Main Line electrification gets go-ahead
  166 - 10150 - Intercity Express Programme (IEP) - ongoing discussion
  163 - 13396 - Electrification - what are the real benefits?
  156 - 818 - Crossrail - ongoing discussion, merged topic
  154 - 1109 - Extending Crossrail to Reading - ongoing discussion, merged topic
  146 - 15079 - Boxing Day Trains
  144 - 13540 - Loadings, cancellations and other issues
  128 - 3266 - Swindon to Kemble re-doubling - ongoing discussion and updates
  119 - 13635 - Daytime Traffic on the TransWilts
  103 - 13640 - DMU cascade
  100 - 2338 - Okehampton-Tavistock. Discussion on reopening and potential use as a diversionary route
  100 - 11558 - Annoying / amusing use of completely irrelevant stock photos to illustrate news articles

And once I had the results, and had posted them up [here], there was no further need for the program. Checking comprises looking through the above, sanity checking it - and I'm not actuall bothered if there's a line or two missing or if the counts are slightly wrong. SO no need for a formal test harness and manual process to see that it's fine. I did test by folowing some of the links I had created, and quickly scanned just in case there were any deleted topics or similar that had come up.

Code - nice little example in PHP, written for text output to screen. Although PHP is a web based language written for the web, helper code such as this does a wonderful job for us, run on the web server at the command line. Please forgive the lack of code comments - no point in having any for a one-off!

  <?php
  mysql_connect("127.0.0.1","fgw","password_goes_here");
  mysql_select_db("fgw");
  $counter = "";
  $q = mysql_query("select id_topic,subject from smf_messages where postertime > 1388574638");
  while ($row = mysql_fetch_row($q)) {
    $counter[$row[0]]++;
    $subject[$row[0]] = preg_replace('/^Re:\s+/','',$row[1]);
    }
  arsort($counter);
  foreach (array_keys($counter) as $id_topic) {
    if ($counter[$id_topic] < 50) break;
    print ("$counter[$id_topic] - id_topic - $subject[$id_topic]\n");
  }
  ?>


Much of our work is PHP based - happy to teach you the subject in 2015. We have updated our course agendae and material so that our PHP courses - learning to program in PHP and now include Object Oriented PHP as part of the main course. PHP programmers who are not familiar with OO technices - please get in touch as we can arrange for a Object Orientation in PHP day for you - a special one day course to run for one delegate if need be, on a mutually conventient day that's not otherwise booked.