Short-fiction updated again

0

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!

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 linux server to run them from. Currently proud of; Mags Direct - a site I created for my work at the Frontline Group. An online magazine shop, which I created with almost zero budget within a week (since had a full theme upgrade). Found at https://magsdirect.co.uk/ Married, one cat. Beer fanatic (wife probably says bore) - real ales and craft beers. I have spent for too much on home brew gear, I create full mash craft beers. I spend a lot of time either going to gigs or organising them - I'm part of a small bunch of friends putting on DIY Punk shows called "The Scary Clown Presents..." our website can be found here; https://thescaryclownpresents.co.uk/ 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 *