Thursday 7 April 2016

How do I avoid this mess?

First of all, is this the best subreddit for a technical question? I'm trying to clean up this code and make it less of a Russian doll situation. Any advice would be appreciated!posts: function (connection, options){ //Find out what topic we are at connection.query("SELECT * FROM topic WHERE url = '" + options.parameters.topicTitle + "'", function (err, topicRows, fields) { if (err) throw err; //Find out what subcategory this is connection.query("SELECT * FROM `subcategory` WHERE `url` = '" + options.parameters.subcategoryTitle + "'", function (err, subcategoryRows) { if (err) throw err; //find out what the category title is connection.query("SELECT * FROM `category` WHERE `url` = '" + options.parameters.categoryTitle + "'", function (err, categoryRows) { if (err) throw err; //get all the appropriate posts connection.query("SELECT * FROM `post` WHERE `topic_fid` = '" + topicRows[0].topic_id + "'", function (err, postRows) { options.res.render('postList', { category: categoryRows[0].title, categoryLink: categoryRows[0].url, subcategory: subcategoryRows[0].title, subcategoryLink: subcategoryRows[0].url, topic: topicRows[0].title, topicLink: topicRows[0].url, posts: postRows, }); }); }); }); }); },

Submitted April 07, 2016 at 04:44PM by snahrvar

No comments:

Post a Comment