Short-fiction updated again
I’ve made a tough decision and removed the ‘voting’ part of my story website (http://www.short-fiction.co.uk), after giving it a long consideration.
Luckily it wasn’t that hard to unhook the code – as there is only one php page to display all the stories – I just pass a ‘story id’ to the page, and it looks up it’s own content.
The trouble with having ‘votes’ for stories is that it is open to abuse, and an early ‘bad vote’ could put off both people from reading a story, and also the writer from ever contributing again. So voting out, and hopefully more feedback to the writers in.
I’m working on a ‘random story of the day/week/month’ – to help push people towards stories they might not have looked at – currently I’ve just put a random story up on the main page, which is selected every time you display the page.
Using MySQL to get a random row from the database is actually very easy – and there are many ways to do it. Instead of generating random ids/row numbers in my PHP code, I decided to let MySQL do all the work, and just give me a random row. For those of you who want to get random data out of the database, here’s how I do it – but remember it’s not the only way!
$sql_random_story = “SELECT * FROM sf_stories sfs where sfs.status=’S’ and category<>18 ORDER BY RAND(NOW()) LIMIT 1”;
$random_story_result = @mysql_query($sql_random_story,$connection) or die(mysql_error());
$sql_data_story = mysql_fetch_object($random_story_result);
Obviously the table name and where clause is specific to my set-up – but it gives you an idea. The sql will pull back a random ordered dataset, but limited to 1 row (that’s the important bit) – so you only get 1 row back. Unlike Oracle DB, the ordering is applied before the row limit – in oracle if you limit to x rows, that happens before the sort is applied, which is often useless!