Couple of questions PHP + Querying Databases

Soldato
Joined
1 Mar 2003
Posts
5,508
Location
Cotham, Bristol
Couple of quick questions

1. Go to radiotimes.com and look at the tv listings, programmes are split on a grid pattern, the size of the pattern is dependant upon the length of the programme. I don't know the term for this grid type thing, what would it be called in php?

2. The tv listings data is stored in some sort of database, but say you also wanted users to be able login and show their favourites receive reminders etc etc. Would this user information be stored in the same database, or would there be two databases that somehow cross query each other?
 
1. Nothing to do with PHP (apart from pulling the data). The size of the columns and how much they span etc will be CSS. Let me know if you need expansion on that!

2. Definitely a different database. The TV listings will also be made up of a lot of different databases too. For example:

Database: Channels
Fields: id, channelname, terrestrialchannel, skychannel [etc]
Example: 1, BBC One, 1, 1

Database: Programme
Fields: id, programmename, starttime, endtime, repeat, type, channel [etc]
Example: 25, The Alan Titchmarsh Show, 19040239, 34873982, No, TV, 3

For favourites there'll just be a favourites database which cross references your user ID with the channel id or the programme id.

etc

Why are you asking? Might help us give a relevant reply :).
 
Thanks. Surprised by your second answer, I do mean databases not tables within databases, your example looks like separate tables?

I'm asking because I've designed the programmes/channels database, just wondering if I should be adding extra tables to it for user information or to keep the two separate.
 
Yeah sorry, I meant tables :p. Unsure if they'd use separate databases for each table/group of tables or not. Someone who works on larger corporate sites might be able to answer that :).
 
Ok so a very rough and guessed way that they might do it...

You've got the two database entries for start time and end time for the show (probably/hopefully in Unix format, ie seconds since epoch - see time() for more info). Subtract start time from end time and that'll give you the run time in seconds (let's say it's a 30 minute show, so 1800).

Now the area that displays the shows is a fixed width, say 500px. That's divided into 3 "hours", so 166 pixels per hour. A quick bit of calculation and that's ~0.046 pixels per second. So for our 30 minute show it'd be 82.8 pixels wide (and you'd calculate that in PHP ala...):

PHP:
$progStart = $row['start'];
$progEnd = $row['end'];
$progLength = $progEnd - $progStart;

$cellWidth = $progLength * 0.046;

Then just drop the $cellWidth in where needed. That's how I would do it anyway, but probably not how a multi-million pound company does it :p.
 
One of the columns I have is duration in minutes so that should be pretty easy.

I was more talking about the HTML/CSS side of things, just a dynamic table with variable cell widths?
 
Back
Top Bottom