I am starting a new project trying to create a web application for an electronic programme guide for TV. This is not going to be a large scale project, but just something that I can use to learn web application programming. I am going to be using PHP for this.
Before beginning coding for the application, there is a crucial question that is bugging me. Since the application would involve large use of database and/or XML files for data storage, I am confused how to implement the architecture for the application. Please bear with me for this beginner question.
How should I be implementing the architecture of the application?
For example, there are going to be around 50 channels with (50 * N) number of shows. What I am thinking is:
- Put the show description in an XML file.
- Put the channel names in a table in the database.
- Put the show names and IDs in another tables and fetch show description from the XML document.
What the above architecture lacks is how to actually implement the time-tracking. I mean I know when a particular show starts and ends but where do I “best” store that information? In the database or in the XML file? And how do I “best” display the information?
Do you have a better suggestion than the above architecture?
From the kind of data that I assume TV programme guides store, it really looks like you can store everything inside a relational database. I see no advantage in using the filestsytem or XML files.
The queries for time-tracking should be very straightforward in SQL.
You could consider using a schema such as the following (using MySQL in this example):
The
showstable should define each show.show_idis a surrogate key, and you can even make it generate a unique serial number automatically. Thenamefield is just name field, and thedescriptionfield has atextdata type which can store a variable amount of text.The
channelstable should be quite straightforward. Again we’re using a surrogate key as achannel_id. I’m not sure if channels have some unique standard code that can be used as a natural key instead, but you should be safe with a surrogate key.Then the
channel_slotstable allocates show slots to each day of each channel.I might be wrong, but I think most TV programme guides do not strictly define a day as starting and ending at midnight. Sometimes the day might at at 2:00am of the following day, and a programme that start at 1.30am and ends at 2.00am would make part of that day. If this is the case, that’s the reason for using a
dayfield in this table. In this field we can define the day that this show belongs to, in terms of “programme guide days”.The
slot_idis again a surrogate key, and thechannel_idandshow_idfields are foreign keys to the relevant table. Thestartandendfields simply define the accurate start and end times of the show. If you will be inserting shows where the show times are not yet defined, you may want to insertNULLin these fields. Another option could be to use another field as a flag to mark if show times are confirmed of not.If you are going to use MySQL as your DBMS, note that the InnoDB storage engine supports foreign key constraints, while the default MyISAM engine does not. However, only the MyISAM engine supports full text indexing. This may be useful if you intend to allow your users to search for text inside the show descriptions.
To give you an example of the above schema, let’s populate some data in it:
This is how our tables look like now:
Now let’s say that the time now is
2010-07-17 17:45:00and you want to display what is the next show on Channel 1:Result:
Then the following query displays the remaining schedule of the day for Channel 1:
Result:
And so on. I hope this gets you going in the right direction. You should also make sure to research on database indexes, an important topic not covered in my answer.