Ticker / Which language?

Associate
Joined
10 Feb 2009
Posts
1,893
Location
Leicester
Hey

I'm redoing my website and want to have a 'ticker' box that presents random fact about me every day or every so many seconds / minutes.

I'll use something like code academy and google to hopefully teach me a bit of coding if it isn't to hard (already know a bit of Java script, php)

What would be the best language to code this in and would it be easy?

(obviously it would just be facts ive put in myself on the back end then it picks one at random every day etc and displays it live on my site)
 
Associate
Joined
7 Nov 2010
Posts
87
Location
Cambridge, UK
Javascript, optionally with something on the server-side.

Javascript is pretty much the only thing that can interact with the clients web-browser (without the client requiring extra plugins)

The simplest method is to hard code your "facts" into an array and then have it pick one at random after a pre-determined time.

You could also have PHP generate this array of facts from a database too if you wanted something a little more fancy, and if you want overkill you could use AJAX to request a new fact from your server instead of sending the whole list to the client.
 
Soldato
Joined
4 Oct 2008
Posts
6,693
Location
London
You could also have PHP generate this array of facts from a database too if you wanted something a little more fancy, and if you want overkill you could use AJAX to request a new fact from your server instead of sending the whole list to the client.

Something like this is what I would go with, have a simple PHP script that picks a random fact from a list of facts that are stored in a database, and then on the front end use AJAX (not to difficult through jQuery) to just request the facts. You can even do slightly more advance things like request 10 facts at a time, and cycle through them so you can reduce the amount of requests you make, if you decide to cycle through them quickly.

http://api.jquery.com/jQuery.ajax/
 
Associate
Joined
10 Nov 2013
Posts
1,808
Agree with everything that's been said. The jquery/ajax/php route is a bit more complicated but I'd argue it's the 'correct' way to do it - and if you're looking at this as more of a learning exercise then you'll get a lot more out of it doing it this way.
 
Associate
OP
Joined
10 Feb 2009
Posts
1,893
Location
Leicester
Thanks for the info guys, I'll look into it then :)

What file type would the facts be stored in if I go the PHP route?
 
Last edited:
Associate
Joined
10 Nov 2013
Posts
1,808
It depends if you are using or want to use a database or not. If so it will just be a simple table that you can query. If not then there's a few options:

  • store all the facts in a file (CSV/XML/JSON format would make it easy to read using PHP)
  • store a fact per file
  • hard-code a list of facts in a PHP array
 
Soldato
Joined
3 Jun 2005
Posts
3,119
Location
The South
Considering the simplicity of task, i'd keep it as simple and as straightforward as possible unless you have a specific reason for the need to either store the data in a DB or flat file, or use ajax or server-side - which you don't from what you've specified.

It's a bit of a waste to overcomplicate on a simple task and if this is a learning exercise for ajax or server-side/PHP then i'd be looking at a more challenging task to use these technologies on.
 
Last edited:
Back
Top Bottom