Pub Night

Pub Night is a website that I set up for a group of friends who go out drinking once a week in Cheltenham. We’ve been doing it for years and a few years ago now Nick and I came up with the idea of building a website for it. I went for a Wiki based site but because we wanted “standard” information for each pub I built a rather large extension for it which basically allows us to use Data pages to hold the information on the pub and then for each pub we have a simple page which contains some tags which allow us to display the information in a controlled format.

Pub Night is primarily based in Cheltenham but has details on some pubs outside of the town, primarily in GloucesterLondonUpton upon Severn and Market Drayton.

There is also a sub group of Pub Night called Out Of Town Pub Night Group (or OOTPNG for short) which once a month goes to a good pub within a reasonable driving distance of town. The venues and drivers and approximate dates had been decided and I went to load them into the system so I could put up a page with the 2009 locations. That is where the problems began. The code that drives pub night talks directly to the database behind the wiki which means that information on pubs normally comes out in the order the pubs were added into the database. To support the new page I added two new fields to the data set – nextvisit and driver. But I wanted to sort the information on the nextdate. So I’ve had to go in a recode how the “where” part of the extension works so that rather than just trawling through the pubs in turn and if they match the criteria displaying the information I now go through the pubs once and grab a “sort” field from the data (if specified) and then I sort the list of pubs on that and then process each one in turn to get the information. Sounds easy doesn’t it?

Well it is when you are dealing with text fields because you can simply build the array with the Digraph and the “sort” field and then use the php functions asort and arsort. Date fields are another matter entirely. Pub Night stores its dates in dd/mm/yyyy format which do not sort. PHP has a strtotime function which converts “human” date formats into unix timestamps. Those we can sort easily so problem solved. Afraid not because strtotime doesn’t like dd/mm/yyyy. So I had to us the php mktime function to parse the PN date format into something I could then pass into strtotime to get the timestamp and now its all working.

Now all I have to do is fix the problem with null dates which upset it (silently, they just spew errors into the error log!)

This entry was posted in Computing and tagged , . Bookmark the permalink.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.