Top Gear type score thing

Maljonic

Can't get enough of FH
Joined
Dec 22, 2003
Messages
1,297
I wonder if anyone knows of a simple script so I could make a race scoreboard like this: http://www.topgear.com/content/tgonbbc2/laptimes/celebrity/ where you can add a name and time (via a log in), and tick a box for wet, and it updates the scoreboard accordingly. Say with twenty viewable entries and a more link to see them all if there's more than 20.

Or if there's a tutorial where I can learn how to make something like this with php and mysql, or someone can just show me how to do it if it's easy? I've tried Googling it but all I come up with is highscore add ons for flash games and such like.

P.S. doesn't have to be PHP, just so long as it works, I just can't think of a better method.
 

Padwah

Fledgling Freddie
Joined
Dec 25, 2003
Messages
127
Are you any good at PHP and MySQL anyway as something like that would be a piece of piss, unfortunately seeing as I do all my work in ASP or .NET I can't tell you exactly how you do it. Bt, you'd need a table in the database with two columns, one for the name and one for the time. Then you run a query to select the names and times from the database order by time in ascending order and limit it by however many results you want to show per page. You can then page through the results by changing the limit off-set to return the next page of results.
 

Maljonic

Can't get enough of FH
Joined
Dec 22, 2003
Messages
1,297
Well I sort of figured I'd have to do something like that, only I'm not that good with mysql and php just yet. I was starting to get the hang of it when Jonty was around to help, but that was ages ago and I forgot it all again. :)
 

Maljonic

Can't get enough of FH
Joined
Dec 22, 2003
Messages
1,297
I've made a database table with firstname, lastname, laptime and wet/dry. I have the last one set to dry as default and have a tick box to make it wet in the submit form.

So I have the db and the form, which I guess if the easy part. Now I have to figure out how to get the information from the form to the db with PHP.

I'm a bit confused about the lap time though, it will be in minutes and seconds but I'm not sure how to put this in the form. Should it be a text field where you enter 1.24 for 1 minute 24 seconds, or should I make seperate fields for minutes and seconds and, if so, how do I transfer that in the right way to the db?

Also should the db table field for the laptime be TIME or INT?
 

wyrd_fish

Fledgling Freddie
Joined
Dec 27, 2003
Messages
537
i'd store lap time as seconds (INT) and devide by 60 for mins and mod by 60 for seconds in your script
 

Maljonic

Can't get enough of FH
Joined
Dec 22, 2003
Messages
1,297
That sounhds quite complicated if I'm getting it right. Would I need to have an entry box for minutes and a seperate one for seconds, then times the minutes by 60 and add it to the seconds then send that number to the database? Then how would I display it back to the score table in minutes and seconds?
 

Padwah

Fledgling Freddie
Joined
Dec 25, 2003
Messages
127
In Wierd_Fysh's example you have one field in your DB for the time which you store in seconds, so a lap time of 1 min 25s would be 85s. Your SQL query would pull out all of the lap times ordered by time in ascending order but to get it to display in some sort of sensible format you'd need to do a bit of creative formatting.

To display the minutes part you would need to divide the time by 60 and only show the first two digits, to display the seconds part you need to use the math function MOD (85 Modulo 60).

Not knowing PHP I just google and came up with this: http://www.indigorose.com/forums/showthread.php?t=14669 for converting seconds to minutes and seconds.
 

SheepCow

Bringer of Code
Joined
Dec 22, 2003
Messages
1,365
That's not PHP, but yeah something like

PHP:
$minsandsecs = 185;

$mins = floor($minsandsecs / 60);
$secs = $minsandsecs % 60;

echo "{$mins}m {$secs}s";

Would output: "3m 5s"

It doesn't matter what your input looks like. you could ask for the total in seconds and store it directly, or ask for the total in minutes and seconds then manipulate it into seconds and store it.
 

Maljonic

Can't get enough of FH
Joined
Dec 22, 2003
Messages
1,297
Does it matter if I want to put decimal places in the seconds, like 1min 24.56 seconds?
 

wyrd_fish

Fledgling Freddie
Joined
Dec 27, 2003
Messages
537
nope

you can just store as millisecs and do a bit more maths

mins = ((ms/10)/60)
secs = (ms/10)
ms2 = (ms%10)
 

Maljonic

Can't get enough of FH
Joined
Dec 22, 2003
Messages
1,297
Would that mean adding another box on the input form for 10ths of seconds?
 

Shovel

Can't get enough of FH
Joined
Dec 22, 2003
Messages
1,350
You could, or perhaps better would just be to interpret it server-side and split the 'time' string on ':' and '.' characters to get your minutes, seconds and milliseconds. Just specify the input format in text next to the input and pre-fill it with a suitable placeholder mm:ss.ms or suchlike.

Multiple input boxes for a single field ('time') are quite unpleasant to use, although I accept they reduce the amount of erroneous input you can get I think mm:ss.ms is a simple enough concept that few users will get it wrong (bar typos, which will happen if you use multiple inputs too).
 

Maljonic

Can't get enough of FH
Joined
Dec 22, 2003
Messages
1,297
Well to be honest I'm not actually planning on using this for anything, I just wanted to learn how to do it. I did just make a static score board for a site, which is why I started thinking about it, but they only want to update it like once a month with one person added each time so it's hardly worth making a database for that.

I just thought the idea seemed simple and a good thing to learn on. I haven't even managed to add anything at all via a form to the db yet, still don't quite follow everything. I'm just sort of picking stuff up slowly out of a book I bought and a few websites, but I have to do it a bit at a time because it makes my head swim a bit and my poor mind clouds over.

I will get there though, I know just by looking at it that it can't be all that difficult. Gets a bit scary when people keep mentioning maths. :)
 

Users who are viewing this thread

Top Bottom