Short-fiction updated again


I’ve made a tough decision and removed the ‘voting’ part of my story website (, 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!

Author: Krispy

Webmaster of this and many websites over the years. I've been a Senior developer (Java JEE and Oracle DB, specialising in SEAM/JSF/Hibernate web development). Ex Lead Developer at New Scientist magazine, where I worked on creating a new WordPress based website, using almost 100% custom created widgets, plugins and theme. My own projects include websites created in WordPress and custom written with PHP and MySQL, and have my own dedicated Windows server to run them from. Currently proud of; My several darts websites; - Darts, Beers & Cheers, and - Darts Open Tournament database. I also run websites for over ten of the elite players on the PDC tour, and two for darts management companies. Married, one cat. Beer fanatic (wife probably says bore) - I'm becoming an expert in real ale, craft ales, and Belgium and German beers. If expert means enjoying them. I've also dabbling in doing a bit of extract home brew. CAMRA member, and now regular guest judge for the local Beer festival. I've even created the 'semi official' web app for the Peterborough Beer festival (2nd largest in the country). Play a little darts (badly for Stilton), and watch .. LOTS of darts. Also a fan of the local footy team - UP THE POSH!

Share This Post On

Submit a Comment

Your email address will not be published. Required fields are marked *